for

The for loop will iterate through the loop, starting from the specified initial condition and will iterate through the statements enclosed within the { code block } until the test is false. The initial condition, test and iterator are separated with a ;

 

for (initialiser; test; iterator ) {
statements ;
}

 

#include <stdio.h>
int main() {

	for (int i=0; i<5; i++) {
		printf("The value of i is now: %dn",i) ;
	}
	return 0 ;
}

Compile & run:

The value of i is now: 0
The value of i is now: 1
The value of i is now: 2
The value of i is now: 3
The value of i is now: 4

Leave a Reply