Introduction to C++
switch-case to compare our variables with other values. But what if we need to do something a hundred times? A thousand times? A million times?
Loops are designed for just such cases!
It allows you to loop your program under certain conditions.
Structure of while loop:
We have summed up (
x+=1) 992 times in this case.
The loop ran while
x + y was not equal to
As soon as the expression
x + y became equal to
result, the loop ended, and we got the root of the equation (
The loop may not start if the condition is not satisfied.
It is crucial to make sure that the loop has an exit condition, that is, that the loop will not be infinite.
The infinite loop example:
Choose the correct version of the while loop:
Select the correct answer