0
What is a while loop?
The loop in a program.
4 ответов
+ 2
This video explains it well:
https://youtu.be/7pAXm7WEA2I
+ 8
The while loop is used to repeat a section of code an unknown number of times until a specific condition is met.
+ 3
While something is True, do something.
So if you have a program that counts something, you can make it stop at a certian number, otherwise count forever .
0
It basically says while a certain condition is met execute the given code
For example if we have a variable declared as 5 and we write a while loop to increase the number and print it put:
(not sure if this is a valid while loop it's just to illustrate the concept)
int a = 5;
while (a < 5) {
a++; // increase a's value.
cout << a << endl; // print a's value.
}
This code will print the following:
6
7
8
9
Hope this helps.