- How while loop works?
- The while loop evaluates the test expression.
- If the test expression is true, codes inside the body of while loop is evaluated.
- Then, the test expression is evaluated again. This process goes on until the test expression is false.
- When the test expression is false, while loop is terminated.
- Flowchart of while Loop.
- prog to print valuve from 1 to 10 using while loop:-
#include<iostream.h>
void main()
{
int k;
k=1;
while(k<=10)
{
cout<<k<<endl;
k++;
}
}
note:-it's just a sudo code if its not executing on your device make some changes in the further code this is only for understanding logic.
0 Comments