MQL5Book/Scripts/p2/StmtLoopsWhile.mq5

36 lines
1.2 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:09:41 +02:00
//+------------------------------------------------------------------+
//| StmtLoopsWhile.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
int i = 5;
// while(--i) // warning: expression not boolean
while(--i > 0) // condition is updated in place
{
Print(i);
}
while(i < 10) // condition check is separated from...
Print(++i); // ...affecting variable update
// loop until user command
while(!IsStopped())
{
Comment(GetTickCount());
Sleep(1000);
}
Comment("");
}
//+------------------------------------------------------------------+