Chapter 05
Chapter 05
Continued…
int number = 6;
while (number <= 5)
{
cout << "Hello\n";
number++;
}
int number = 1;
while (number <= 5)
{
cout << "Hello\n";
}
Continued…
int x = 1;
do
{
cout << x << endl;
} while(x < 0);
Continued…
General Format:
1) Perform initialization
2) Evaluate test expression
If true, execute statement
If false, terminate loop execution
3) Execute update, then re-evaluate test
expression
int count;
Continued…
int x, y;
for (x=1, y=1; x <= 5; x++, y++)
{
cout << x << " plus " << y
<< " equals " << (x+y)
<< endl;
}
int sum = 0;
for (int num = 0; num <= 10;
num++)
sum += num;
Continued…
Continued…
Inner Loop
Outer Loop
int main()
{
ofstream outputFile;
outputFile.open("demofile.txt");
int main()
{
ofstream outputFile;
string name1, name2, name3;
int main()
{
ifstream inputFile;
string name;
inputFile.open("Friends.txt");
cout << "Reading data from the file.\n";
Continued…
inputFile.open(filename.c_str());