All loops are used for the repetition. Repetition is very
important c++ or any other programing language. So, in while loop, first we declare one object and initialize it with any
number which I want to use. Then we use key word while and use small brackets
and write the condition in between the brackets. Then use curly brackets, write
the statement which we want to execute and below use the increment operator.
So, you can watch the code to understand the use of while loop in c++.
Code:
#include <iostream>
using namespace std;
int main()
{
int i;
i=0;
while(i<=20)
{
cout<<i<<endl;
i++;
}
}
Output:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Hope you understand the use of simple while loop in c++.
0 Comments