Repeat until - Codea freezes

Hi there,

I am new to both Lua and Codea and just ran into a problem I cannot get my head around.

I am trying to use a repeat until loop to simply print the numbers 400 to 800. As soon as I execute that piece of code Codea freezes.
I get similar problems when using while loops.

Can anybody tell me whats going on? Thank you!

-- Use this function to perform your initial setup
function setup()
    -- Variables
    i = 400
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(255, 255, 255, 255)

    -- Do your drawing here
    repeat
         print (i)
         i = i + 1
    until i == 800
end

The function draw is executed 60 times a second (ideally).

Your code sets up i to be 400 initially, then the first time it executes the draw function it increments i until it reaches 800. The second time the draw function is executed i is already at 800 fulfilling the requirement of your repeat until loop.

It’s not freezing, you just aren’t telling it to do anything else in the draw function

Thanks, but there is more code In the draw loop I should have posted earlier. When I said freeze, I was talking not reacting at all - I can’t even get back into the editor but have to manually close the app and restart.

Here is the whole code, just in case:


-- Use this function to perform your initial setup
function setup()
    -- Variables
    x = 900
    w = 150
    h = 100
    
    counter = 3
    parameter.watch("CurrentTouch")
    parameter.watch("x")
    
    th = HEIGHT - 20
    tw = WIDTH 
    tht = HEIGHT - 40
    i = 400
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(255, 255, 255, 255)

    -- Do your drawing here
    repeat
         print (i)
         i = i + 1
    until i == 800

    
    fill(0, 0, 0, 255)
    font("MarkerFelt-Thin")
    text("Leben:", 40, th)
    text(counter, 80, th)
    
    lineCapMode(SQUARE)
    strokeWidth(5)
    stroke(0, 0, 0, 255)
    line(0, tht, WIDTH, tht)
    
    
    if CurrentTouch.state == BEGAN then
        fill(16, 178, 197, 255) 
    elseif CurrentTouch.state == MOVING then
        fill(255, 0, 0, 255)
    elseif CurrentTouch.state == ENDED then
        fill(210, 218, 16, 255)
    end

    sprite("Documents:fant", CurrentTouch.x, CurrentTouch.y, w, h)
    
    fill(255, 0, 110, 255)
    
    if x == 0 then 
        sound(SOUND_JUMP, 39249)
        x = x + 1
        else
            x = x - 1
            ellipse(x, 300, 100)
    end
    
    
    if x == CurrentTouch.x then
        sound(SOUND_EXPLODE, 6)
        counter = counter -1
       -- h = h - 10
       -- if h == o then
         --   h = 0
         --   w = 0
      --  end
    end
    
-- end function draw()  
end

Any idea?

You are doing the whole repeat the first time draw gets called. The second time draw gets called, i is greater than 800 and keep incrementing, so the repeat never stops, locking up draw.

Me slaps head! Got it, thanks for your patience :wink: