for statement

In this section we introduce you the language to program TipControl. It is used in the Macros and Events Section.

for – loop
if
while
dowhile
return

The for loop in TipControl is similar to languages like C++, it is a control structure that allows code to be executed repeatedly based on a condition. The for loop is especially useful when you know in advance how many times you need to execute a block of code.

Structure of a for Loop

A typical for loop is structured as follows:

  1. Initialization: This step is executed once before the loop begins. It is often used to set an initial counter variable.
  2. Condition: Before each iteration of the loop, this expression is evaluated. If the condition is true, the loop body is executed. If it is false, the loop terminates.
  3. Update: This step is executed after each iteration of the loop body. It is typically used to increment or decrement the loop counter.

Let’s look at a simple example to illustrate how a for loop works:

// This loop will print numbers 1 to 5

    for (i = 1, i <= 5,i+=1) {

        lib.log(“Number:” +  i);

}

Explanation:

  • Initializationi = 1  initializes the loop counter i to 1.
  • Conditioni <= 5; checks whether i is less than or equal to 5. If this condition is true, the loop continues; otherwise, it exits.
  • Updatei+=1 increments the loop counter i by 1 after each iteration, i++ like in C is not supported yet

Each time through the loop, the value of i is printed, resulting in the following output:

Number: 1 Number: 2 Number: 3 Number: 4 Number: 5