Menu
Brokers
MT4 Forex Brokers
MT5 Forex brokers
PayPal Brokers
Skrill Brokers
Oil Trading Brokers
Gold Trading Brokers
Web Browser Platform
Brokers with CFD Trading
ECN Brokers
Bitcoin FX Brokers
PAMM Forex Brokers
With Cent Accounts
With High Leverage
Cryptocurrency Brokers
Forums
All threads
New threads
New posts
Trending
Search forums
What's new
New threads
New posts
Latest activity
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Reply to thread
Forums
Trading Platforms
MetaTrader 4
Help!! How to only iterate z once? For loop syntax
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
[QUOTE="nadia, post: 184554, member: 68500"] [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 } //+------------------------------------------------------------------+ [/CODE] 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? [/QUOTE]
Insert quotes…
Verification
Post reply
Top
Bottom
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…