【发布时间】:2019-07-03 06:26:31
【问题描述】:
我是 MQL4 的新手,并通过那里的网站学习代码。
阅读break; 代码并来到这个源代码。
这是我试图理解的代码。 请帮助我了解变量的答案是如何得出的。 提前致谢。
void OnTick()
{
int a, b, L, s, S, A, B; // (---Variable Initializing.---)
L=1000; // (---Value for L is 1000 assigned.---)
for ( a = 1; a < L / 2; a++ ) // (---Now value of a=1
{ /* and a is smaller then 500
so condition is true
and value of a is 499 Now---)
*/
b = ( L / 2 ) - a; // (---Now b=1000/2=500-499, So value of b is 1)
s = a * b; // (---Now s=499*1=499---)
if ( s <= S ) break; /* (---After using if statement,
s is smaller then or equal to S.
there is no value assigned to "S".
So how the condition gets TRUE.---)
*/
A = a; // (---now Value of A is 250---)
B = b; // (---now Value of B is 250---)
S = s; // (---now Value of A is 62500---)
}
Comment( " S= ", S,
", A= ", A,
", B= ", B
);
return;
}
我的问题是:
if(s<=S) 语句如何为真并循环中断以回答S=62500, A=250, B=250?
删除if 语句后,答案是 S=499、A=499、B=1。
【问题讨论】:
标签: mql4