Otared Kavian schrieb am 24.08.2023 um 12:50:

On 24 Aug 2023, at 06:03, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> wrote:
[…]

I would drop the column check in this case.

    for i = 0,9 do
        context.startxrow()
            context.startxcell()
                context(i)
            context.stopxcell()
            context.startxcell()
                context(math.mod(i*i,10))
            context.stopxcell()
            context.startxcell()
                context(i)
            context.stopxcell()
            context.startxcell()
                context(math.mod(2*i*i,10))
            context.stopxcell()
        context.stopxrow()
    end

Wolfgang

Indeed this is much more elegant… It feels so good to be on this list and learn from such insights :-)

We don't even need the math.mod function because Lua added with version 5.1 a modulo operator,
the loop to create the row can now be changed to

    for i = 0,9 do
        context.startxrow()
            context.startxcell()
                context(i)
            context.stopxcell()
            context.startxcell()
                context(i * i % 10)
            context.stopxcell()
            context.startxcell()
                context(i)
            context.stopxcell()
            context.startxcell()
                context(2 * i * i % 10)
            context.stopxcell()
        context.stopxrow()
    end

Wolfgang