Page 1 of 1
Break function
Posted: Thu Apr 15, 2021 4:55 pm
by Wim Gielis
Hi all,
I know that the Break function is not supported in TI. But in the past it never bite me, until today.
Looking at this code:
Code: Select all
c = 1;
While( c > 0 );
If( 'X' @= 'Y' );
Break;
EndIf;
c = c + 1;
If( c > 3 );
Break;
EndIf;
End;
The process will run forever and bring the TM1 server to the ground. Why ?
The first IF is never True.
The second IF should be executing and lead to a Break and escape the loop, it does not.
Now here's something important: if I uncomment the first Break, the second executes !
So it looks like you cannot have 2 Break statements within the loop.
Did anyone come across this one ?
Re: Break function
Posted: Thu Apr 15, 2021 8:26 pm
by Emixam
Hello Wim,
I notice this behavior couple months ago. I just ran your code and was stuck in a infinite loop.
However, if you have nested while loops it will works (as long as there is only 1 break statement in each loop)
This will be executed successfully:
Code: Select all
i = 1;
WHILE( i > 0 );
IF( i > 10 );
Break;
ENDIF;
c = 1;
WHILE( c > 0 );
IF( c > 3 );
Break;
ENDIF;
c = c + 1;
END;
i = i + 1;
END;
Ever since I realized this issue I'm using a numerical value as a break statement:
Code: Select all
c = 1;
While( c > 0 );
If( 'X' @= 'Y' );
#Break;
c = -1;
EndIf;
c = c + 1;
If( c > 3 );
#Break;
c = -1;
EndIf;
End;
I am using PA 2.0.8
Re: Break function
Posted: Thu Apr 15, 2021 8:49 pm
by Wim Gielis
Thanks for the confirmation, these were exactly my thoughts too.
I think I will continue using Break and make sure there's only 1 of it, if there are 2 then yes, a numeric value will do.
I just find Break so much better than escaping loops with numeric values like -1 or 0 or 999 or some such.
Re: Break function
Posted: Fri Apr 16, 2021 9:55 am
by Mark RMBC
Hi Wim,
I use Break too, so this is good to know.
If you put Sleep (100) before the first Break does this resolve it?
Interestingly adding an asciioutput into both IF statements outputs 2 files if a break statement is there.
regards,
Mark
Re: Break function
Posted: Fri Apr 16, 2021 10:58 am
by Wim Gielis
Mark RMBC wrote: ↑Fri Apr 16, 2021 9:55 am
Hi Wim,
I use Break too, so this is good to know.
If you put Sleep (100) before the first Break does this resolve it?
Interestingly adding an asciioutput into both IF statements outputs 2 files if a break statement is there.
regards,
Mark
Yes, the Breaks are ignored leading to endless loops too.
Re: Break function
Posted: Fri Apr 16, 2021 11:14 am
by Mark RMBC
Hi Wim,
so the code below also leads to an endless loop?
Code: Select all
c = 1;
While( c > 0 );
If( 'X' @= 'Y' );
Sleep(100);
Break;
EndIf;
c = c + 1;
If( c > 3 );
Break;
EndIf;
End;
Interesting it doesn't for me.
Mark
Re: Break function
Posted: Fri Apr 16, 2021 11:16 am
by Wim Gielis
I haven’t tried Sleep yet, I should do that more by the way !
Re: Break function
Posted: Fri Apr 16, 2021 1:15 pm
by Emixam
Hello,
Apparently, replace the Sleep() function with any other functions/line of code and the process will still be completed successfully !
Code: Select all
c = 1;
While( c > 0 );
If( 'X' @= 'Y' );
# Replace GetProcessName() with something like z = 1 + 2 and it will still works !
GetProcessName();
Break;
EndIf;
c = c + 1;
If( c > 3 );
Break;
EndIf;
End;
Re: Break function
Posted: Fri Apr 16, 2021 1:27 pm
by Wim Gielis
Weird ! But then the advantage of the simplicity of Break is gone too
