Break function

Post Reply
Wim Gielis
MVP
Posts: 3113
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Break function

Post 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 ?
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Emixam
Posts: 139
Joined: Tue May 21, 2019 3:33 pm
OLAP Product: TM1
Version: PA 2.0.x
Excel Version: 2016
Location: The Internet

Re: Break function

Post 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
Wim Gielis
MVP
Posts: 3113
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Break function

Post 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.
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Mark RMBC
Community Contributor
Posts: 292
Joined: Tue Sep 06, 2016 7:55 am
OLAP Product: TM1
Version: 10.1.1
Excel Version: Excel 2010

Re: Break function

Post 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
Wim Gielis
MVP
Posts: 3113
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Break function

Post 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.
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Mark RMBC
Community Contributor
Posts: 292
Joined: Tue Sep 06, 2016 7:55 am
OLAP Product: TM1
Version: 10.1.1
Excel Version: Excel 2010

Re: Break function

Post 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
Wim Gielis
MVP
Posts: 3113
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Break function

Post by Wim Gielis »

I haven’t tried Sleep yet, I should do that more by the way !
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Emixam
Posts: 139
Joined: Tue May 21, 2019 3:33 pm
OLAP Product: TM1
Version: PA 2.0.x
Excel Version: 2016
Location: The Internet

Re: Break function

Post 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;
Wim Gielis
MVP
Posts: 3113
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Break function

Post by Wim Gielis »

Weird ! But then the advantage of the simplicity of Break is gone too 😉
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Post Reply