"HARD WORK BEATS TALENT WHEN TALENT DOSEN'T WORK HARD."
"HARD WORK BEATS TALENT WHEN TALENT DOSEN'T WORK HARD."
If you don't know number of iteration in advance. How much iteration go long.? The do while loop is same as a while loop with one important difference.
The body of do while loop is executed once, before checking the condition. Hence, the do while loop is executed at least once.
It execute until the condition not go false. Keep preforming iteration until condition not become false.
do { statement; } while(condition);
Let's suppose you want to print the number from 1 to 10. You can't write the 10 times printf function to print the all number. It is very time consuming process. To solve this problem we use while loop condition.
#include<stdio.h> #include<conio.h> void main() { int i=1, n; int f1 = 0, f2 = 1, f3; clrscr(); printf("Enter the Number :- "); scanf("%d",&n); printf("%d %d ",f1,f2); do { f3=f1+f2; printf("%d ",f3); f1=f2; f2=f3; i++; } while(i<=n-1); getch(); }
Enter the Number :- 5 0 1 1 2 3 5