Mr. Walt's class

 

Redlands Conservatory C++ Core Language Programming!

 






   

 

 

C++ Programming for Scratch programmers!


 

 

 What follows are Mr. Walt's samples to run and modify on the compiler at:
http://www.tutorialspoint.com/compile_cpp_online.php


// Sample #1: C++ "WHILE" Loop.  (Loops while a condition is true.)


#include <iostream>

using namespace std;

 int main ()

{

   int a = 1;

   while( a < 13 )

   {

       cout << "value of a: " << a << endl;

       a=a+1;

   }

    return 0;

}


//  Sample #2.  "FOR" loop.  (Loops as long as a n> condition is true.)


#include <iostream>

using namespace std;

 int main ()

{

    for( int a = 1; a < 13; a = a + 1 )

   {

       cout << "value of a: " << a << endl;

   }

    return 0;

}


//Sample #3.  "DO" Loop. (Loops at least once, then continues as long as condition is true.)


#include <iostream>

using namespace std;

int main ()

{

   int a = 1;

   do

   {

       cout << "value of a: " << a << endl;

       a = a + 1;

   }while( a < 13 );

   return 0;

}


 //Sample #4.  Loop forever.


#include <iostream>

using namespace std;

 int main ()

{

   for( ; ; )

   {

      printf("This loop will run forever.\n");

   }

   return 0;

}


 















Web site contents Copyright Walt Noon 2015, All rights reserved.