MT4智能交易编程教程-循环操作符 do while
for 和 while 从起点循环检测终止,不在循环末端。第三种循环操作符do - whileo每次循环重复后,在最后检测终止状态。循环主体至少执行一次。
- do
- operator;
- while(expression)
-
复制代码首先执行操作符,然后计算表达式。如果是true,那么操作符再次执行。如果表达式变成false,循环终止。 Note If it is expected that a large number of iterations will be handled in a loop, it is advisable that you check the fact of forced program termination using the IsStopped() function. 示例: - //--- 计算斐波纳契数列
- int counterFibonacci=15;
- int i=0,first=0,second=1;
- int currentFibonacciNumber;
- do
- {
- currentFibonacciNumber=first+second;
- Print("i = ",i," currentFibonacciNumber = ",currentFibonacciNumber);
- first=second;
- second=currentFibonacciNumber;
- i++; // 没有这个操作符会出现一个无限循环!
- }
- while(i<counterFibonacci && !IsStopped());
-
复制代码
|