Help!! How to only iterate z once? For loop syntax

nadia

Trader
Aug 12, 2020
15
2
6
38
Code:
//+------------------------------------------------------------------+
//|                                                     question.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
// A:
   for(int x=0; x<100; x++)
      if(x==1)
         for(int y=0; y<100; y++)
            if(y>x) // DEAL WITH THE PREVIOUS DETERMINED X AND FINALLY
              {
               Print("y ",y);
               break; // PRINTS Y ONLY ONCE CORRECT
              }

// B:
   for(int x=0; x<100; x++)
      if(x==1)
         for(int y=0; y<100; y++)
            if(y>x) // DEAL WITH THE PREVIOUS DETERMINED X AND FINALLY
               for(int z=0; z<100; z++)
                  if(z>y) // DEAL WITH THE PREVIOUS DETERMINED Y AND FINALLY
                    {
                     Print("z ",y); // PRINT ONLY FIRST Z THAT IS ABOVE Y WHICH IS ABOVE X
                     break; // !!!!! ONLY ONCE THOUGH !!! THIS ONE PRINTS MANY Z's; NOT CORRECT
                    }

//2 versions; A stops at 2 and B does not. Why does the first A only print one iteration of y and the B iterates many iterations of z? I need B. to behave like A and only print ONCE the z value that is larger than x and y
  }
//+------------------------------------------------------------------+
Running this you get one y and many zs ; how to just have 1 z above y?

Is this worth it or just have it break and save to variables faster bc break ends the whole loop?
 
Last edited:

nadia

Trader
Aug 12, 2020
15
2
6
38
Code:
      for(int x=0; x<100; x++)
         if(x==1)
            for(int y=0; y<100; y++)
               if(y>x) // DEAL WITH THE PREVIOUS DETERMINED X AND FINALLY
                 {
                  for(int z=0; z<100; z++)
                     if(z>y) // DEAL WITH THE PREVIOUS DETERMINED Y AND FINALLY
                       {
                        Print(__LINE__," ",GetLastError()," ",GetMicrosecondCount()," z ",z," ",GetMicrosecondCount()," ",GetLastError());
                        break; // !!!!! ONLY ONCE THOUGH !!! THIS ONE PRINTS MANY Z's; NOT CORRECT
                       }
                  break;
                 }
 
Last edited: