The ones who are crazy enough to think they can change the world are the ones who do.- Steve Jobs
A loop enables a programmer to execute a statement or block of statement repeatedly. The need to repeat a block of code arise in almost every program.
There are three kinds of loop statements you can use. They are
In for loop control statement, initialization, condition and increment are all given in the same loop.
#include <stdio.h> int main() { int i; for(i=0; i<10; i++) { printf("%d ",i); } return 0; }
Here, for loop will iterate until the conditional statement at the center of for-loop fails.
In While loop, initialization, condition and increment are all done in different lines.
#include <stdio.h> int main() { int i = 0; while(i<10) { printf("%d ",i); i++; } return 0; }
Here, while condition iterate until the condition inside it become false.
Here, it is same as while loop, but it will execute a block of code once irrespective of condition.
#include <stdio.h> int main() { int i = 0; do { printf("%d ",i); i++; }while(i>10); return 0; }
Though 0 > 10 tends to false block of code following do was executed successfully.
We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.
© Copyright 2019