C++


  ITERATIVE INSTRUCTIONS

Iteration (Latin iteratio - repetition) - repetition activity (usually multiple) the same instruction (or multiple instructions) in a loop.

  LOOP ”do … while”

    do { instructions } while (condition);

We use it when we do not know the exact number of repetitions, but we want the given instruction to be executed at least once. Instructions are executed as long as the given condition is true.
Example:

  ile=0;
  do
   {
   cout << ”Number=”;
   cin >> number;
   if (number>0)
   {suma+=number;ile+=1;)
   }
   while (number!=0);
   mean=suma/ile;
   cout.precision(2);
   // number of decimal places
   cout<<fixed<<mean;
   // fixed-print manipulator


  LOOP „while”

   while (condition) { instructions }

We use it when we do not know the exact number of repetitions, but it is possible that the given instruction will not be executed even once. Instructions are executed as long as the condition is true.
Example:

   float x;
   cout << ”Enter a numeric factor:”;
   cin >> x;
   while (x<= 0 || x>=1)
   {
   cout << ”The value given is incorrect” ;
   cout << ”Enter a number in the range (0; 1)”;
   cin >> x;
   }