Typically, a for loop is for when you know how many times you will loop, and a while loop is for when you don't. A do while is for when you want something to happen at least once.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
for (int i = 0; i < 10; i++)
{
cout << i '\n';
}
int num;
ifstream myFile("myData.txt");
while ( myFile >> num)
{
cout << num << '\n';
}
char choice;
do
{
cout "Make a choice, or q to quit: ";
cin >> choice;
} while (choice != 'q');
#include <iostream>
usingnamespace std;
int sumDiv(int x)
{
int s = 0;
for ( int s = 1; i < x; ++ 1)
{
if(x % i == 0 )
s += i;
}
return s;
}
int main()
{
for(int i =1; i < 2000; i++)
{
int a == sumDiv(i);
if (a == i)
cout << i << endl;
}
}