How does the "for loop" work in C?

 How does the "for loop" work?

The for loop in C first evaluates the initialization expression. If it evaluates true, the first iteration of the loop will run, if false the loop will not run. The code within the loop will executed and then the loop will be updated by the loop expression and re-evaluated. If it is evaluated as true again, the body will run again. If it is false, the loop will exit.

How do computer programmers write a "for loop"?

The basic syntax of a for loop in C is the for statement followed by a number of control expressions separated by semi-colons:

for (A;  B;  C)

{

body

}

A = initialize expression - the expression that will be used in the first evaluation

B = conditional expression - the expression that will be used to evaluate whether the loop should run again or exit

C = loop expression(increment/decrement) - this updates the variable for each iteration of the loop

The body is the block of code that will run as long as the conditional expression is true.

Comments