While Loop in C++ programming

The while loop is used to repeat a block of code as long as a specific condition is true. As long as the condition is true, the loop will keep running the block of code, and as soon as it becomes false, it will stop.

A while loop's basic structure is as follows:

Syntax:-

while (condition) {
    // Code to be repeated
}

Example:-

#include <iostream>

int main(){
int i = 1;
while (i <= 10) {
    cout << i << " ";
    i += 2;
}
return 0;
}

output:-

1 3 5 7 9