Topic: Programming

Online Help

Iteration blocks

You can have simple iterations inside a Calcpad program. For that purpose, you have to define a "repeat-loop" block:

  • #Repeat n
  • Code to be executed repeatedly
  • #Loop

The symbol n stands for the number of repetitions. Instead of n, you can put a number, variable or any valid expression. If the result of the expression is not integer, it is rounded to the nearest one. You can exit the repeat-loop cycle prematurely by putting #Break inside the block. It will make sense only if you combine it a conditional block. Otherwise, it will always break at the same line, without performing any loops. A typical "repeat-break-loop" will look like this:

  • #Repeat
  • Code to be executed repeatedly
  • #If condition
  • #Break
  • #End if
  • You can have more code here
  • #Loop

You can use #Continue instead of #Break. The program will skip the remaining lines, return to the top of the conditional block and continue with the next iteration. You can omit the number of repetitions n only if you are sure that the condition will be satisfied and the loop will brake sooner or later. Anyway, to avoid infinite loop, the number of iterations is limited to 100 000 if nothing else is specified.

Besides repetitive calculations, you can use loops to generate repetitive report content (like table rows). If you want to hide the iteration details, you can use output control directives (see the previous section). For example, you can enclose the "repeat-loop" block with #Hide and #Show statements.