// pre- vs. post- increment/decrement
#include <iostream>
using namespace std;

int main() {

  int x,y,count;

  // while loops
  cout << "############ WHILE ############\n";
  
  x=0; // initial condition
  y=5; // boundary value
  count = 0; // count the loop iterations for comparison
  
  cout << "*******************************\n";
  cout << "Pre-increment (x = 0, y = 5, while(++x < y)):\n";
  while(x++ < y){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Post-increment (x = 0, y = 5, while(x++ < y)):\n";
  while(x++ < y){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Pre-decrement (x = 0, y = 5, while(x < --y)):\n";
  while(x < --y){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Post-decrement (x = 0, y = 5, while(x < y--)):\n";
  while(x < y--){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  // do-while loops
  cout << "######### DO-WHILE ############\n";
  x=0;
  y=5;
  count = 0;

  cout << "*******************************\n";
  cout << "Pre-increment (x = 0, y = 5, while(++x < y)):\n";
  do{
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }while(x++ < y);
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Post-increment (x = 0, y = 5, while(x++ < y)):\n";
  do{
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }while(x++ < y);
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Pre-decrement (x = 0, y = 5, while(x < --y)):\n";
  do{
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }while(x < --y);
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Post-decrement (x = 0, y = 5, while(x < y--)):\n";
  do{
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }while(x < y--);
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  // for loops
  cout << "############# FOR #############\n";

  x=0;
  y=5;
  count = 0;

  cout << "*******************************\n";
  cout << "Pre-increment (for(x = 0; x < 5; ++x)):\n";
  for(x = 0; x < 5; ++x){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Post-increment (for(x = 0; x < 5; x++)):\n";
  for(x = 0; x < 5; x++){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Pre-decrement (for(y = 5; y > 0; --y)):\n";
  for(y = 5; y > 0; --y){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Post-decrement for(y = 5; y > 0; y--)):\n";
  for(y = 5; y > 0; y--){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;

  cout << "*******************************\n";
  cout << "Pre-increment (for(x = 0; ++x < 5; ++x)):\n";
  for(x = 0; ++x < 5; ++x){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Post-increment (for(x = 0; x++ < 5; x++)):\n";
  for(x = 0; x++ < 5; x++){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Pre-decrement (for(y = 5; --y > x; --y)):\n";
  for(y = 5; --y > x; --y){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  x=0;
  y=5;
  count = 0;
  cout << "*******************************\n";
  cout << "Post-decrement for(y = 5; y-- > x; y--)):\n";
  for(y = 5; y-- > x; y--){
    cout << "x: " << x << ", ";
    cout << "y: " << y << endl;
    count++;
  }
  cout << count << " iterations.\n";
  cout << "*******************************\n\n";

  return 0;
}
