Sometimes we want a C program to repeat something again and again so, a loops is used to make a program do something more than one time.
Loop Types :
for loop | while loop | do-while loop |
---|---|---|
A for loop is used to execute and repeat a statement block depending on a condition which is evaluated at the beginning of the loop. Example : for(i=1; i<=10; i++) |
A while loop is used to execute and repeat a statement block depending on a condition which is evaluated at the beginning of the loop. Example : i = 1; |
A do-while loop is used to execute and repeat a statement block depending on a condition which is evaluated at the end of the loop. Example : i = 1; |
A variable value is initialized at the beginning of the loop and is used in the condition. | A variable value is initialized at the beginning or before the loop and is used in the condition. | A variable value is initialized at the before the loop or assigned inside the loop and is used in the condition. |
A statement to change the value of the condition or to increment the value of the variable is given at the beginning of the loop. | A statement to change the value of the condition or to increment the value of the variable is given inside the loop. | A statement to change the value of the condition or to increment the value of the variable is given inside the loop. |
It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.