Tech Blog   »   Home   »   Coders Forum   »   Computer Directory   »   Math Calculators   »   RSS:Directory|Forum 




// While loop in C++ with output show below.

#include <iostream>

using namespace std;

 

int main()

{

       int num = 1; // num variable controls the count from 1.

                    // initialize counter starting at 1.

 

       while (num <= 7) // Loop - number controls how many times.

       {

              cout << num; // Show the number each time.

              num++;       // Add 1 to the variable num.

              cout << " - Hello world!\n";

       }

 

       cout << "\n";

       return 0;

}

 

/* ====================== output ============================

1 - Hello world!

2 - Hello world!

3 - Hello world!

4 - Hello world!

5 - Hello world!

6 - Hello world!

7 - Hello world!

 

Press any key to continue . . .

*/// ========================================================

 

Validated with no errors:

Valid XHTML 1.0 Transitional     Valid CSS!


Site Map