RetroBASIC

Retrogamecoding(.org) => EGSL => Topic started by: Peter on November 20, 2012, 09:32:19 PM

Title: Exit for
Post by: Peter on November 20, 2012, 09:32:19 PM
Hi Cyber,

there is no EXIT FOR, what can I use for it?
Title: Re: Exit for
Post by: cvirus on November 20, 2012, 09:53:54 PM
just use
Code: [Select]
end
Title: Re: Exit for
Post by: Peter on November 20, 2012, 10:17:48 PM
Hi cvirus,

No, isn't. 
D:\EGSL\julia.lua:24: '<eof>' expected near 'end',  is what i got.

I think is rather BREAK, but I'm not sure about BREAK.
Title: Re: Exit for
Post by: Tomaaz on November 20, 2012, 10:56:36 PM
You should use break and end.

Code: [Select]
for x = 1, 1000 do
    if x > 500 then break end
    print(x)
end

Here is an explanation: http://www.lua.org/pil/4.4.html (http://www.lua.org/pil/4.4.html).
Title: Re: Exit for
Post by: cvirus on November 21, 2012, 09:49:54 AM
A simple for loop is like:
Code: [Select]
for i = 1,3 do print(i) end
The break statement immediately ends the current loop when executed, if you whant to complete the for loop then you shouldn't use break.

Code: [Select]
for i = 1, 3 do
    if ( i == 2 ) then break end
    print( i )
end
Title: Re: Exit for
Post by: Tomaaz on November 21, 2012, 10:54:24 AM
The break statement immediately ends the current loop when executed...
That's exactly what exit for in BASIC does.
Title: Re: Exit for
Post by: Bereb on November 21, 2012, 11:14:47 AM
I think is rather BREAK, but I'm not sure about BREAK.

Yes, it's break. You can see an example in this topic (http://retrogamecoding.org/board/index.php?topic=17.0) :

Quote
(...)
for i = 0, 50 do
    zre2 = zre*zre
    zim2 = zim*zim
    if zre2 + zim2 > 4 then
       color(255-(i+5), i*5, i)
       dot(x,y)
       break
    end
    zim = 2*zre*zim+cim
    zre = zre2-zim2+cre
end
(...)

break exits the for-loop (and not the if-block, as we might think)
Title: Re: Exit for
Post by: Peter on November 21, 2012, 11:23:29 AM
A well done help,  inbuilt  in EGSL IDE would be more exact.
Title: Re: Exit for
Post by: Cybermonkey on November 21, 2012, 02:17:27 PM
EGSL is Lua, so it's the Lua way.  ;D BTW, "break" is a highlighted keyword in the IDE.
Title: Re: Exit for
Post by: Peter on November 21, 2012, 02:23:21 PM
LOL
Title: Re: Exit for
Post by: cvirus on November 21, 2012, 02:43:00 PM
I think is rather BREAK, but I'm not sure about BREAK.

Yes, it's break. You can see an example in this topic (http://retrogamecoding.org/board/index.php?topic=17.0) :

Quote
(...)
for i = 0, 50 do
    zre2 = zre*zre
    zim2 = zim*zim
    if zre2 + zim2 > 4 then
       color(255-(i+5), i*5, i)
       dot(x,y)
       break
    end
    zim = 2*zre*zim+cim
    zre = zre2-zim2+cre
end
(...)

break exits the for-loop (and not the if-block, as we might think)

That´s right, sorry if i wan´t very clear.