-
-
Notifications
You must be signed in to change notification settings - Fork 1
While Loop
Artemis edited this page May 13, 2023
·
2 revisions
The while
loop is a type of loop used to execute a certain set of instructions or code until a certain condition is met.
The syntax for a while
loop in C++ is as follows:
while (condition) {
// code to be executed
}
Where condition
is a boolean expression.
Here is an example of a while
loop in C++:
int x = 0;
while (x < 10) {
cout << x << endl;
x++;
}
This code will print out the numbers from 0 to 9 and then exit the loop.
The break
and continue
statements can be used inside a while
loop. The break
statement will exit the loop and the continue
statement will skip the current iteration and continue with the next iteration.
The while
loop is a powerful tool for executing a set of instructions until a certain condition is met. It can be used in combination with the break
and continue
statements to control the flow of the loop.