Laurand Osmeni

Let's build a faster web.


How do I use the while loop in C++.

So what the while loop does? we write the code once, and then it is going to run it forever or as many times we want to.

Creating a variable laurand with the value 1.

int laurand = 1;

Now the syntax of while loop is the while, and the inside the parthenses is the test of the code.

while(laurand <= 10)

It runs the code again and again.

cout << "It is doing the while loop" << laurand << endl;

The loop will keep running forever till the program crashes, otherwise if we want something like to tell while loop stop till to this number 10 and then add 1 number or more, example +1, +2, +5.

laurand = laurand +1;

The program will loop till reaches the 10, then it adds 1 more and stops at 11.

Watch live in action creating the program, or scroll below to copy the entire code.

while loop C++
How do I use while loop in C++.
#include <iostream> using namespace std; int main () { int laurand = 1; while(laurand <= 10) { cout << "It is doing the loop" << laurand << endl; laurand = laurand +1; } return 0; }

Feel free to use the code.

Last update .

Navigate between pages.