Answer to Question #146087 in C++ for Yazal

Question #146087
What is while loop?
1
Expert's answer
2020-11-22T23:44:32-0500

The while loop loops through a block of code as long as a specified condition is true:

while (condition) {
  // code block to be executed
}

Example:

int i = 0;
while (i < 5) {
  cout << i << "\n";
  i++;
}

In the example we print value of i and then increase it by 1 until it is less than 5. After i=4 we do i++ again, but this time the condition in while will be false, so the loop will not run again.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog