/*
  Working blocks of code. Scope of variables. Defining variables inside scopes. (C++ only) see  Nyhoff P124.

  // e.g. branching statement     IF or FOR
     {   start of new scope
       :
       :
     }   end of scope


*/

#include <iostream>
using namespace std;

double w=2.0;



int main()
{
   double sum=0.0;
   for (int i=0;i<5;i++)
      {
          double x=i*3.141592;
          cout << i << " " << x << endl;
          
          sum=sum+x;
      }
   cout << "Sum=" << sum << endl;







   double x=1.0;

     {                                          // starts block 1 of code
        double y=2.0;

            {                                   // starts block 2 of code
               double z=3.0;                    // z is defined here
               cout << "x=" << x << "  y=" << y << "  z=" << z << endl;

            }                                   // z only exists inside block 2

//   cout << "x=" << x << "  y=" << y << "  z=" << z << endl; // compilation fails y,z not defined here.

     }                                          // y only exists inside block 1

//   cout << "x=" << x << "  y=" << y << "  z=" << z << endl; // compilation fails y,z not defined here.



   return 0;
}
