Jumping out of a Loop

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times

Jumping out of a Loop

Post by Docara »

Hello again,

It looks like I will need to jump out of a While loop. Is there any other way to do it apart from connection points? Also, would this then mean the stack would increase in size as the pointers wont get cleared down?

Thanks
Matt
Last edited by Docara on Mon Aug 14, 2017 12:41 pm, edited 1 time in total.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Jumping out of a Loop

Post by Benj »

Hi Matt,

We are investigating adding Break and Continue icons for FC8.

For now you can either use connection points or you can add a statement to the while loop decision.

For example to only loop when varA is not 0 and varB is less than 10 you would do this.

Code: Select all

(varA != 0) && (varB < 10)
Also, would mean the stack would increase in size as the pointers wont get cleared down?
Goto's only work inside the macro your currently in and a while loop does not use stack, therefore jumping around using connection points won't add garbage or clutter to the stack but is generally considered bad practise as it can make it harder to follow the program execution when debugging.

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times

Re: Jumping out of a Loop

Post by Docara »

Hi Ben,
Also, would mean the stack would increase in size as the pointers wont get cleared down?

Goto's only work inside the macro your currently in and a while loop does not use stack, therefore jumping around using connection points won't add garbage or clutter to the stack but is generally considered bad practise as it can make it harder to follow the program execution when debugging.
Sorry to be a pain!! just to help me understand (my knowledge is from the Z80 days) is it not the case the starting point address of loops (also subroutines and interrupts) are stored on the Stack and then removed when an equivalent of a Return command (old school phrase) is encountered?

At the moment the main routine is the one which will require me jumping out of a loop and not a macro.

Thanks
Matt
Last edited by Docara on Mon Aug 14, 2017 3:31 pm, edited 1 time in total.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: Jumping out of a Loop

Post by LeighM »

Subroutines and interrupts get "called" and cause a push of pc to the stack, which pops on a return (as you stated)
This does not apply to jumps, loops, go to etc

Post Reply