Tech Blog » Home » Coders Forum » Computer Directory » Math Calculators » Subnetting RSS:Directory|Forum
C++ Source Code: Implementations, Beginners
Home » Coders Community: Forum

// While loop.
#include <iostream>
using namespace std;
int main()
{
int num = 1; // Initialize counter starting at 1.
while (num <= 7) // Loop - number controls how many times.
{
cout << num; // Show the number as it increments.
num++; // Increment by adding 1 each iteration.
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 . . .
===========================================================*/
The above source code is C++, using a while loop.