break in while loop and goto(call)/return with label

tanutanu

Well-known member
Hi,

Please consider adding break statement to avoid meaningless while loop.
Even though a matched condition was found by nested if statement in while loop, the loop continues until while condition is filled.
Only I can do is cancel macro itself. Before do that I can remember the fact in boolean and call itself again. with the boolean value, I can check the running state in if statement and branch. It works good but not simple.

Jumping to another macro is available by run macro action. However, I have to remember a returning position when I want to get back to next statement in original macro file.
I made so many functions(subroutine) in one my library file. It is very easy to maintain same procedure in single source. Now I emulate the behavior using if triggered statement and global variable to remember a returning position. I would like to replace it with goto(call) and return with unique label, regardless self or another macro file.

Cheers:)
 

FrameXX

Well-known member
Hi,

Please consider adding break statement to avoid meaningless while loop.
Even though a matched condition was found by nested if statement in while loop, the loop continues until while condition is filled.
Only I can do is cancel macro itself. Before do that I can remember the fact in boolean and call itself again. with the boolean value, I can check the running state in if statement and branch. It works good but not simple.

Jumping to another macro is available by run macro action. However, I have to remember a returning position when I want to get back to next statement in original macro file.
I made so many functions(subroutine) in one my library file. It is very easy to maintain same procedure in single source. Now I emulate the behavior using if triggered statement and global variable to remember a returning position. I would like to replace it with goto(call) and return with unique label, regardless self or another macro file.

Cheers:)
Hi. If I would make it clear, what you are asking for is action block that if some conditions are met would move you to a completely different part of the macro. Am I saying that right?
 

tanutanu

Well-known member
I'm talking two different things.
One is a typical function in many languages when matching inline if condition and exit the while/for loop.
When I execute a while loop 10K times looking for certain keyword but want to find at least one case, if found within 100 times, still running 9900 times in the while loop.
Now we don't have break statement, so I imitate using cancel action with stopwatch or run this macro to exit and run again.

The other, you like to make sure, is jump with label like typical goto statement without any conditions. MD has global variable, so return value support is not needed.
If enabled to return from another code block not only SAME macro file but ANOTHER, it is very useful. I imagine it as same as include another file(but a part of labeled code block), or funcrion/procedure in another languages.
MD macro is NOT running parallelly asynchronous process like multi threading, running linear like single threading. When you use "run B macro" action with immediate execute option in A macro file, A macro file is stop running until B is sleeping or finished everything. This feature is helpful to guarantee the processing order as well. Currently it depends on sleep action.
 
Last edited:

Pseudocyclic

Well-known member
When I execute a while loop 10K times looking for certain keyword but want to find at least one case, if found within 100 times, still running 9900 times in the while loop.
Why not use Repeat Actions While... keyword match has not yet been found?
 

Pseudocyclic

Well-known member
When you use "run B macro" action with immediate execute option in A macro file, A macro file is stop running until B is sleeping or finished everything. This feature is helpful to guarantee the processing order as well. Currently it depends on sleep action.
Why not use Wait Until Trigger action immediately after Macro Run action?
 

tanutanu

Well-known member
Why not use Repeat Actions While... keyword match has not yet been found?
You don't image what I wrote. I'm talking about a typical "break" situation in a while loop with nested if statement.
Another example, in single while(MD doesn't have for loop but the same thing) loop for 10k or more line text with a loop couner to check A string at least 10 times and B string at least 100 times but under 300 times. It has possibility to be found fewer loops. Once found them, exit the loop is good for performance reason. Only parsing text is not heavy because of just a example, but another case for real purpose is more complicated.
 

tanutanu

Well-known member
Why not use Wait Until Trigger action immediately after Macro Run action?
I'm talking about typical subroutine call behavior like funcrion or procedure mainly. Do you know that? returning next statement before the first jump is not easy in MD.
 

guilhermgonzaga

New member
I see what you mean, but... that is bad practice even in full-blown programming languages. Jumping to an arbitrary action.

As for the break situation, you can fix it with a counter. Run a while loop with two conditions: a variable to see if it should stop (boolean) and a counter (integer) to see if the limit (10k) was reached. Count +1 on every iteration and set the boolean to stop early.
 

tanutanu

Well-known member
I see what you mean, but... that is bad practice even in full-blown programming languages. Jumping to an arbitrary action.

As for the break situation, you can fix it with a counter. Run a while loop with two conditions: a variable to see if it should stop (boolean) and a counter (integer) to see if the limit (10k) was reached. Count +1 on every iteration and set the boolean to stop early.
guilhermgonzaga,

What I really want is function/procedure call though;)
MD already had run macro action. It works as goto but runs itself again or make another macro run from the 1st action statement only.
Jumping to label is helpful if I want to skip some code blocks(and I always want to return).
I emulate typical function behavior with a global variable which contains caller macro name, caller code name and arg value(s) if I need. The caller is just a statement simply writes the global value, runs library macro, then the caller macro skips all statements and dies.
Once my library macro is invoked, I check the trigger fired and the global variable at if statement of a code block. If matched, it processes something and writes macro name, "function" name and return value on the same global variable, then runs the caller macro and dies. The caller macro detects the global variable changed by if statement, it finds returning point to continue and runs again.
If the caller macro always suspended and kept on waiting for another macro canceled or finished, I wouldn't need to call again. However, it depends on another macro which has wait action or not.

Pseudocyclic gave me a good suggestion, if I rewrite to execute by variable change trigger when the caller macro runs again. No trigger execute a macro when it is called by run macro command in another macro. Actions are running directory, just ignore triggers.

Thanks for the suggestion of stopping while loop:) It is simply but good idea. I didn't remember because I always use break in other languages.
 
Last edited:

guilhermgonzaga

New member
[...]
Jumping to label is helpful if I want to skip some code blocks(and I always want to return).
I emulate typical function behavior with a global variable which contains caller macro name, caller code name and arg value(s) if I need. The caller is just a statement simply writes the global value, runs library macro, then the caller macro skips all statements and dies.
Once my library macro is invoked, I check the trigger fired and the global variable at if statement of a code block. If matched, it processes something and writes macro name, "function" name and return value on the same global variable, then runs the caller macro and dies. The caller macro detects the global variable changed by if statement, it finds returning point to continue and runs again.
If the caller macro always suspended and kept on waiting for another macro canceled or finished, I wouldn't need to call again. However, it depends on another macro which has wait action or not.
[...]

OK, that made it clear, thanks.
 
Top