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:
- Initialization: This step is executed once before the loop begins. It is often used to set an initial counter variable.
- Condition: Before each iteration of the loop, this expression is evaluated. If the condition is
true
, the loop body is executed. If it isfalse
, the loop terminates. - 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:
- Initialization:
i = 1
initializes the loop counteri
to1
. - Condition:
i <= 5;
checks whetheri
is less than or equal to5
. If this condition is true, the loop continues; otherwise, it exits. - Update:
i+=1
increments the loop counteri
by1
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