Explanation
In darts, there are several ways of looping. One of them is for. for is a looping technique that is often used by programmers in their daily work.
For more details, let's look at the image below
Let's do one surgery at a time.
1. Statement: is a way of writing a for
2. Initial condition: is the starting point for the loop. in the picture it is explained that the beginning of the loop is the number 1.
3. looping condition: is a condition where the loop will be executed until the condition is passed.
4. logic increment: is a way of adding i. there it is explained that i++ which means every iteration, the variable i will increase by 1 (i=i+1).
5. Statements in the loop are the code that we will use later for various variations.
Writing Example
void main(){
for(int i = 1; i<5; i++){
print(i);
}
}
The result is
1
2
3
4
Case Examples
If you are confused about examples, cases. Here are examples of problems and solutions.
even numbers
problem: how to output integers between 1 to 100?
the solution:
void main(){
for(int i = 1; i<100; i++){
if(i%2==0) print(i);
}
}
The result of this loop is an integer between 1 and 100.