Loops / Looping

Loops are used within programs when something needs to be repeated. There are different kinds of loops that you may use:

for loop:

A for loop is a loop that repeats the included instructions a set number of times based on an incremental counter:

for(int x=0; x<10;x++){
     printf("x is: %d\n",x);


A while do will repeat the included code as long as a condition is true. Because the condition is at the top of the loop it is possible that the loop is never executed if the condition it is based on is never true.

	int x=1;
	int y=10;

		printf("x: %d | y: %d\n",x,y);

do / while:

a do while loop is similar to the while loop. The major difference is the evaluation of the condition is at the conclusion of the loop. This means the loop will always execute at least once.

	int x=10;
		printf("x = %d\n",x);