Author Topic: Exit for  (Read 2778 times)

Peter

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

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

cvirus

  • Regular Member
  • Jr. Member
  • *
  • Posts: 77
    • View Profile
Re: Exit for
« Reply #1 on: 20. November 2012, 22:53:54 »
just use
Code: [Select]
end

Peter

  • Guest
Re: Exit for
« Reply #2 on: 20. November 2012, 23:17:48 »
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: 20. November 2012, 23:56:36 »
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: 21. November 2012, 00:39:34 by Tomaaz »

cvirus

  • Regular Member
  • Jr. Member
  • *
  • Posts: 77
    • View Profile
Re: Exit for
« Reply #4 on: 21. November 2012, 10:49:54 »
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: 21. November 2012, 11:54:24 »
The break statement immediately ends the current loop when executed...
That's exactly what exit for in BASIC does.

Bereb

  • Newcomer
  • *
  • Posts: 47
    • View Profile
Re: Exit for
« Reply #6 on: 21. November 2012, 12:14:47 »
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: 21. November 2012, 12:17:36 by Bereb »
Regards, Bertrand :)
** Lubuntu 14.04 (Intel Celeron CPU 2.66GHz - 1280MiB) **

Peter

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

Cybermonkey

  • Administrator
  • Hero Member
  • *****
  • Posts: 626
    • View Profile
    • Home of EGSL
Re: Exit for
« Reply #8 on: 21. November 2012, 15:17:27 »
EGSL is Lua, so it's the Lua way.  ;D BTW, "break" is a highlighted keyword in the IDE.
Best regards,
Cybermonkey

Peter

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

cvirus

  • Regular Member
  • Jr. Member
  • *
  • Posts: 77
    • View Profile
Re: Exit for
« Reply #10 on: 21. November 2012, 15:43:00 »
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.