Get Out from Looping Process.

It is programming trick that can be implemented not only in TM1.

So far from some programming languages I know there are three types of looping

  1. For…Next
  2. While…do or Do…while
  3. Repeat…Until

Loop is part of programming to repeat command as many as maximum counter we defined. The difference between above loops explains below.

  1. For…Next

for..next

The counter start from 1 and will stop after i = 10

The iteration is always 1

  1. While…do

while_end

Line 1: i = 1

Meaning the counter start from 1. You can change it into the number you want.

Line 2: While (i<=10)

To check condition before doing the command inside the loop. If (i<=10) execute the commands inside the loop.

Line 3: Write.Output(i)

It is sample command inside the loop. In this sample, it is algorithm command to write output.

Line 4: i = i +1

Is the iteration. Here you can define your own iteration. In this sample I put plus (+) one (1). But you can put any number as the iteration, depend on your requirement.

Line 5: End While

is the “closing” of the loop, to indicate process to go back to the top, the “opening” of the loop.

  1. Do…While

do_while

It is same with while do (number 2). The difference is it will do the commands inside the looping before checking either the counter value still below the maximum number or not.

  1. Repeat…Until

repeat_untill

  It is same with do..while (number 3). Repeat to execute commands inside the      looping until the system not meet the condition that defined in “until” section

Now, how to get out from the loop if the maximum number haven’t been reached? Maybe there is another condition that has been met and you don’t want system to continue to do the process until maximum iteration reached.

Sample Case:

Read data from table maximum 100 times or until transaction Month <>’Jan’

So the looping should be like this:

sample_case

See line 6:  i = 101

by changing the iteration value into 101, the process will stop once it found that the value of “I” is not less than 100.

That is the way to get out from loop before the iteration reached maximum number. Maybe some programming languages have command “exit” to get out of looping, but this is the basic logic.

about the loop, it is also related to this: Simple Concepts of Turbo Integrating Scripting

Veronika Rotua Gultom

 

 

 

 

 

 

 

 

 

1 thought on “Get Out from Looping Process.

Leave a comment