Intro_loops
Functions
Loops.cpp File Reference
#include <iostream>

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 9 of file Loops.cpp.

10 {
11  int n{5}; // -std=c++11
12 
13 // --------------------------------------- Classical loop
14 // rejecting loop
15  {
16  cout << endl << "Classical loop by for" << endl;
17 
18  // (initialization; continuation?; manipulation)
19  for (int i = 0; i < n; ++i) {
20  cout << " " << i;
21  }
22  cout << endl;
23  }
24 // --------------------------------------- While
25 // rejecting loop
26  {
27  cout << endl << "Loop by while" << endl;
28 
29  int i = 0; // initialization
30  while ( i < n ) { // continuation?
31  cout << " " << i;
32  ++i; // manipulation
33  }
34  cout << endl;
35  }
36 // --------------------------------------- Do While
37 // non-rejecting loop
38  {
39  cout << endl << "Loop by do while" << endl;
40  cout << " wrong for n <= 0 !!" << endl;
41 
42  int i(0); // initialization
43  do {
44  cout << " " << i;
45  ++i; // manipulation
46  }
47  while ( i < n ); // continuation?
48 
49  cout << endl;
50  }
51  return 0;
52 }