Download MetaTrader 5
To add comments, please log in or register
Order the development and track its status via your mobile phone.
pascalboy
238
pascalboy 2013.12.30 09:36 
If you use while in place of if or vice versa.
Does it make difference?
Simon Gniadkowski
Moderator
17994
Simon Gniadkowski 2013.12.30 10:03  
pascalboy:
If you use while in place of if or vice versa.
Does it make difference?
while and if are not equal or equivalent . . . for and while do the same job.
Ian Venner
2583
Ian Venner 2013.12.30 14:49  
if(condition)  // if the condition is true
  
{
 do something  // it does something once
}
 

while(condition) // while the condition is true
{
 do something;  // it does something repeatedly in a loop until condition is false
 break;         // or break out of the loop
}
 
 

In the example above I make the while behave the same as the if because it will do something once then break out of the while loop. If you dont use break you must create another logical end to the loop, otherwise it will loop forever.
/
To add comments, please log in or register