How to exit LOOP in TM1 TI?

Post Reply
Ashleigh W
Posts: 88
Joined: Mon Oct 24, 2016 1:21 pm
OLAP Product: TM1
Version: TM1 Perspectives 10
Excel Version: Excel 2016

How to exit LOOP in TM1 TI?

Post by Ashleigh W »

Hi, how to exit LOOP if certain condition is met in TM1 TI? Is below the correct way?

Code: Select all

nNum = 1;
While( nNum <= 7 );
sNum = NumberToString( nNum );
IF( EXPAND( '%v' | EXPAND( '%sNum%' ) | '%' ) @= 'Test' );
 END;
ENDIF;

nNum = nNum + 1;
END;
TrevorGoss
Community Contributor
Posts: 217
Joined: Thu Aug 15, 2013 9:05 am
OLAP Product: TM1
Version: 10.2.1.1
Excel Version: 14.0.6129.5000

Re: How to exit LOOP in TM1 TI?

Post by TrevorGoss »

Ashleigh W wrote:Hi, how to exit LOOP if certain condition is met in TM1 TI? Is below the correct way?

Code: Select all

nNum = 1;
While( nNum <= 7 );
sNum = NumberToString( nNum );
IF( EXPAND( '%v' | EXPAND( '%sNum%' ) | '%' ) @= 'Test' );
 END;
ENDIF;

nNum = nNum + 1;
END;
you can use the Break keyword from 10.x onwards.

Example:

Code: Select all


x = 1;

While(x <= 10);

	x = x + 1;

	If(x = 5);

		Break;

	EndIf;

End;

Last edited by TrevorGoss on Fri Feb 03, 2017 10:35 am, edited 2 times in total.
Wim Gielis
MVP
Posts: 3117
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: How to exit LOOP in TM1 TI?

Post by Wim Gielis »

Use Break.
Please indent your code and use EXPAND only where it should be used.

Code: Select all

nNum = 1;
While( nNum <= 7 );
  If( Expand( '%v' | NumberToString( nNum ) | '%' ) @= 'Test' );
    Break;
  EndIf;
  nNum = nNum + 1;
End;
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
Ashleigh W
Posts: 88
Joined: Mon Oct 24, 2016 1:21 pm
OLAP Product: TM1
Version: TM1 Perspectives 10
Excel Version: Excel 2016

Re: How to exit LOOP in TM1 TI?

Post by Ashleigh W »

Thanks guys!
Post Reply