C++ While Loop

C++ While Loop


C++ Loops

In computer programming, Loops can execute a set of instruction or block of code until only condition is reached.

we can achieve much more efficiency and sophistication in our programs by making effective use of loops.

There are 3 types of loops in C++.

  • C++ while loop
  • C++ do/while loop
  • C++ for loop

C++ While Loop

A "While" Loop is used to repeat a specific block of code an unknown number of times, until a condition is met.

The Syntax of while loop is as follows:

 

Initialization

while (condition) {

         //loop Statements;

         Update;

}

Example :

Output :