magic number checking

 

Will this code carry on the loop after the continue command or will it just skip it all if the magic number isn't 1


      int total = OrdersTotal();
      for(int i=total-1;i>=0;i--) //if no orders then it won't run through this again
      {
         OrderSelect(i, SELECT_BY_POS);
         if ( OrderMagicNumber() == 1 ) continue;
         int type   = OrderType();
         bool result = false;
         if(type>1)result = OrderDelete( OrderTicket() );
    
         if(result == false)
         {
            Alert("Order " , OrderTicket() , " Error:" , GetLastError() );
            Sleep(3000);
         }  
         
         actionedflag = 0;
         int movedflag=0;
      }
 
SanMiguel:

Will this code carry on the loop after the continue command or will it just skip it all if the magic number isn't 1


https://book.mql4.com/operators/continue

The operator 'continue' stops the execution of the current iteration of the nearest cycle operator 'while' or 'for'. The execution of the operator 'continue' results in going to the next iteration of the nearest cycle operator 'while' or 'for'. The operator 'continue' can be used only in the body of the above cycle operators.


So it won't skip the whole loop, just the current step.

 
robofx.org:

https://book.mql4.com/operators/continue

The operator 'continue' stops the execution of the current iteration of the nearest cycle operator 'while' or 'for'. The execution of the operator 'continue' results in going to the next iteration of the nearest cycle operator 'while' or 'for'. The operator 'continue' can be used only in the body of the above cycle operators.


So it won't skip the whole loop, just the current step.

Should I just use a single if statement then and nest everything inside that because I don't want it to skip any of the steps.

ALternatively if continue skips a step I should be checking to see if the magic ID is != 1


So, this:

OrderSelect(i, SELECT_BY_POS);
         if ( OrderMagicNumber() == 1 ) continue;
Print "HELLO";

will not print hello if the order is 1?
 
SanMiguel:

Should I just use a single if statement then and nest everything inside that because I don't want it to skip any of the steps.

ALternatively if continue skips a step I should be checking to see if the magic ID is != 1


So, this:

I don't see any worth using continue here. Use simple if statement and place your code inside it.

Reason: