xxxxxxxxxx
A "While" Loop is used to repeat a specific block of code an unknown number of times, until a condition is met.
c++ while
xxxxxxxxxx
// Do while loop
// C++ Program to print numbers from 1 to 5
#include <iostream>
using namespace std;
int main() {
int i = 6;
// while loop from 1 to 5
while (i <= 5) {
cout << i << endl;
i++;
}
return 0;
}
while loop that counts to five and outputs 12345
xxxxxxxxxx
int count = 1;
while (count <= 5) {
std::cout << count;
count++;
}
xxxxxxxxxx
//Executes a statement repeatedly, until the value of condition becomes false.
//The test takes place before each iteration
while(condition) {
statement
}