Where is Control Passed to Next in This 'While' Loop?

 

I am going step by step through the manual and have become a bit confused at this page - https://book.mql4.com/operators/continue. My question should be pretty simple for anyone who understands these loops and where control should/shouldn't be passed to next. Here's the full code:

//-------------------------------------------------------------------------------------
// sheep.mq4
// The code should be used for educational purpose only.
//-------------------------------------------------------------------------------------
int start()                               // Special function start()
  {
//-------------------------------------------------------------------------------------
   int
   day,                                   // Current day of the month
   Mons;                                  // Search amount of months
   double
   One_Farm    =1000.0,                   // Sheep on the 1st farm
   Perc_day    =1,                        // Daily increase, in %
   One_Farm_max=50000.0,                  // Sheep limit
   Perc_exit   =10,                       // Monthly output, in %
   Purpose     =35000.0,                  // Required amount on farm 2
   Two_Farm;                              // Current amount of farm 2
//-------------------------------------------------------------------------------------
   while(Two_Farm < Purpose)              // External cycle on history
     {                                    // Start of the external cycle body
      //-------------------------------------------------------------------------------
      for(day=1; day<=30; day++)          // Cycle for days of month
         One_Farm=One_Farm*(1+Perc_day/100);//Accumulation on the 1st farm
      //-------------------------------------------------------------------------------
      Mons++;                             // Count months
      if (One_Farm < One_Farm_max)        // If the amount is below limit,.
         continue;                        // .. don't transfer the sheep
      Two_Farm=Two_Farm+One_Farm*Perc_exit/100;//Sheep on the 2nd farm
      One_Farm=One_Farm*(1-Perc_exit/100);// Remainder on the 1st farm
     }                                    // End of the external cycle body
//-------------------------------------------------------------------------------------
   Alert("The aim will be attained within ",Mons," months.");//Display on the screen
   return;                                // Exit function start()
  }
//-------------------------------------------------------------------------------------

The following section is leading to my confusion:

//-------------------------------------------------------------------------------
      for(day=1; day<=30; day++)          // Cycle for days of month
         One_Farm=One_Farm*(1+Perc_day/100);//Accumulation on the 1st farm
      //-------------------------------------------------------------------------------

Following execution of the 'for' operator body, variable 'One_Farm' will be assigned the value of 1010, and control will then be passed to 'Expression_2' - 'day++', which will increment the value of 'day' by 1 and then pass control to either:

'Expression_1' of the 'for' loop again. This process continues until condition 'day<=30' is false, at which point control can be passed outside of the 'for' loop to the next line of the code - 'Mons++' 

or

'Mons++' which will be executed as soon as the first iteration of 'day++' is completed - regardless of whether or not 'day<=30' is false.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Which of the above is correct?

Thanks for assistance.

 
Documentation on MQL5: Language Basics / Operators / Loop Operator for
Documentation on MQL5: Language Basics / Operators / Loop Operator for
  • www.mql5.com
is executed. The loop repeats expression2 until it becomes false. If it is false, the loop is terminated, and control is given to the next operator. Expression3 is calculated after each iteration. If it is...
 

koranged:

for(day=1; day<=30; day++) One_Farm=One_Farm*(1+Perc_day/100);

'Expression_1' of the 'for' loop again. This process continues until condition 'day<=30' is false, at which point control can be passed outside of the 'for' loop to the next line of the code - 'Mons++' 

or

'Mons++' which will be executed as soon as the first iteration of 'day++' is completed - regardless of whether or not 'day<=30' is false.

Mons++ is not part of the for loop. It executes after the for loop exits.
 
whroeder1:
Mons++ is not part of the for loop. It executes after the for loop exits.

Thankyou.

 

It is good practice to use the value with decimal point when you are manipulating double type values.

The operation (1 + Perc_day / 100) could generate an integer value that would always be equal to 1.

The correct method would be (1.0 + Perc_day / 100.0)

 
Hector Pacheco:

It is good practice to use the value with decimal point when you are manipulating double type values.

The operation (1 + Perc_day / 100) could generate an integer value that would always be equal to 1.

The correct method would be (1.0 + Perc_day / 100.0)

Okay cheers.

Reason: