For Statement

A for loop is useful to repeat a block for certain amount of time.

A for loop repeats a block of code while the condition is true. it has the following syntax.

ለዚህ (variable = expression; condition; increment) {
    // Block
}

In the variable section you can declare a new variable

ለዚህ (መለያ = 0; condition; increment) {
    // Block
}

you could use an already declared variable and update its value

መለያ ሀ; 
ለዚህ ( = 0; condition; increment) {
    // Block
}

or you can leave it empty. but make sure to include the semicolon to indicate that it is the end of declaration section.

ለዚህ (; condition; increment) {
    // Block
}

A for condition is useful to set up a loop breaking condition. which means the loop will only run while the condition section is true.

Warning

leaving the condition empty will cause an infinite loop. so only leave the condition empty when you want an infinite loop.

ለዚህ (መለያ = 0; ሀ < 10; increment) {
    // Block
}

this for loop runs while ሀ is less than 10.

Info

If you don't know how many times the loop should run, it is best practice to use the while loop.

A for increment will be executed after each iteration which will allow you to update a value a after each iteration.

ለዚህ (መለያ = 0; ሀ < 10;  = ሀ + 1) {
    // Block
}

the above example will increment ሀ after each iteration, which means this for loop will run 10 times.