Author Topic: Exit for  (Read 5740 times)

Peter

  • Guest
Exit for
« on: November 20, 2012, 09:32:19 PM »
Hi Cyber,

there is no EXIT FOR, what can I use for it?

cvirus

  • Guest
Re: Exit for
« Reply #1 on: November 20, 2012, 09:53:54 PM »
just use
Code: [Select]
end

Peter

  • Guest
Re: Exit for
« Reply #2 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.

Tomaaz

  • Guest
Re: Exit for
« Reply #3 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.
« Last Edit: November 20, 2012, 11:39:34 PM by Tomaaz »

cvirus

  • Guest
Re: Exit for
« Reply #4 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

Tomaaz

  • Guest
Re: Exit for
« Reply #5 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.

Bereb

  • Guest
Re: Exit for
« Reply #6 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 :

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)
« Last Edit: November 21, 2012, 11:17:36 AM by Bereb »

Peter

  • Guest
Re: Exit for
« Reply #7 on: November 21, 2012, 11:23:29 AM »
A well done help,  inbuilt  in EGSL IDE would be more exact.

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: Exit for
« Reply #8 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.

Peter

  • Guest
Re: Exit for
« Reply #9 on: November 21, 2012, 02:23:21 PM »
LOL

cvirus

  • Guest
Re: Exit for
« Reply #10 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 :

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.