Author Topic: break  (Read 6643 times)

0 Members and 1 Guest are viewing this topic.

Offline Loaf

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
    • View Profile
break
« on: August 22, 2013, 05:38:12 pm »
Noob question here. I have made a preliminary look at questions here, and could not find an answer. I also looked at the Axe Parser Documentation. Is there a way to break out of a loop? Thus far, right before my loop, I have been setting a variable to act as a boolean flag to whether the loop should continue or not. For example,

C = 1
for(T,0,10)
if(C)
code here, in the place of an actual "break" i would put "C = 0"
end:end

However, this is seems clunky and slow, because not only do I have to perform an extra boolean test, I have to finish the loop regardless of the iteration at which C is set.

Based on other questions, this appears to be the right board for this question. However, if not, I apologize in advance.

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: break
« Reply #1 on: August 22, 2013, 05:43:12 pm »
I'd like to say that the boolean is the only solution, you have to  use EndIf to replace the End and put your condition here...
« Last Edit: August 22, 2013, 05:43:50 pm by Eiyeron »

Offline Loaf

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
    • View Profile
Re: break
« Reply #2 on: August 22, 2013, 05:53:33 pm »
Would you be kind enough to give me an example of that? Does it go after a loop or after an if-statement? Practically anything would be better than the way i'm doing it now XD.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: break
« Reply #3 on: August 22, 2013, 05:54:16 pm »
Unfortunately, Axe doesn't currently support continue or break statements. Fortunately, it supports gotos, which can be used to manually implement the break behavior (except in single-argument for loops) like this:


For(A,1,10)
.stuff
Goto Break
.stuff
End
Lbl Break



Continue can be implemented by simply moving the label up a line. And yes, this is the right board for the question. :)
« Last Edit: August 22, 2013, 05:55:21 pm by Runer112 »

Offline Loaf

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
    • View Profile
Re: break
« Reply #4 on: August 22, 2013, 05:56:32 pm »
Why thank you, my dear Runer. That will work perfectly for my feeble needs. :D

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: break
« Reply #5 on: August 22, 2013, 05:57:55 pm »
Runer, what's EndIf so? Isn't that conditionnal break?
Quote from: command list
In loops, it will exit the loop if EXP is true. But it works just like a regular End otherwise.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: break
« Reply #6 on: August 22, 2013, 06:05:17 pm »
EndIf is definitely a slightly confusing command. If the condition following it is false, it acts like a normal End and execution continues at the start of the loop. If the condition is true, execution breaks out of the loop. You may notice that I used both the words break and continue to describe the behavior, because that's essentially what it is: not a conditional break, but a conditional break/continue. The two cases are either break or continue. There is no case in which execution carries on normally inside the loop, so the command marks the structural end of the loop.


EDIT: Fixed the cases being backwards. I promise they're right now.
« Last Edit: August 22, 2013, 06:18:37 pm by Runer112 »

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: break
« Reply #7 on: August 22, 2013, 06:08:07 pm »
Setting the counter variable to the upper limit or a value above the upper limit should make the loop stop as well, but I don't know if it works in axe.
In your code, it means that instaed of setting C to 0 to break, set T to 10 or above.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: break
« Reply #8 on: August 22, 2013, 06:09:16 pm »
Okay! So The only case where that could be used is when the break condition is the last operation in the loop. That's now clear. Thanks!

Offline Loaf

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
    • View Profile
Re: break
« Reply #9 on: August 22, 2013, 06:09:18 pm »
So endif goes inside or at the end of the loop?
From what you've described, I can't see it going at the end, because that would make its 'continue' functionality useless.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: break
« Reply #10 on: August 22, 2013, 06:10:12 pm »
endIf should replace the normal end
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: break
« Reply #11 on: August 22, 2013, 06:11:25 pm »
Endif == true => break; (stop the loop)
Endif == false => continue; ( directly go to loop begin)

(It's what I understood from Runner)

EDITED because Runer got it wrong too!
« Last Edit: August 22, 2013, 06:20:57 pm by Eiyeron »

Offline Loaf

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
    • View Profile
Re: break
« Reply #12 on: August 22, 2013, 06:13:36 pm »
Endif == true => continue ( directly go to loop begin)
Endif == false => break; ( stop the loop).
(It's what I understood from Runner)

After rereading Mr. Runer's post, I am going to agree with you. Also, I now feel like I should have been able to think of AT LEAST setting the iteration variable to a terminating value to break. I'm so uncreative :(

EDIT: Ooh i'm level one now.
« Last Edit: August 22, 2013, 06:14:36 pm by Loaf »

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: break
« Reply #13 on: August 22, 2013, 06:16:30 pm »
Endif == true => continue ( directly go to loop begin)
Endif == false => break; ( stop the loop).

(It's what I understood from Runner)

You know how I said EndIf is a confusing command? Well I got my description of the cases backwards... Oops :P

But you have the idea right. Your post describes exactly how the companion command End!If works. I've edited my original post to correct my mistake.
« Last Edit: August 22, 2013, 06:17:49 pm by Runer112 »

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: break
« Reply #14 on: August 22, 2013, 06:18:42 pm »
(Nice, it's the first step!)

If it works, you can still let it and work later on optimising. Go on and make us some good programs! ;)

i edited my precedent post, Runer. Sorry Loaf!
« Last Edit: August 22, 2013, 06:23:19 pm by Eiyeron »