Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java >&燃气轮机&燃气轮机&燃气轮机&引用;对于(int i=start;i<;num;i+;+;)而言;我_Java - Fatal编程技术网

Java >&燃气轮机&燃气轮机&燃气轮机&引用;对于(int i=start;i<;num;i+;+;)而言;我

Java >&燃气轮机&燃气轮机&燃气轮机&引用;对于(int i=start;i<;num;i+;+;)而言;我,java,Java,我所说的for循环的形式是for(int i=0;i这样写ifor循环的顺序是这样的: Perform the initial expression (e.g. assign initial values) BEGINNING OF 1ST LOOP ITERATION: Check if the condition is true, and end the loop if it isn't Do the body of the loop Increment BEGINNING OF 2ND L

我所说的for循环的形式是for(int i=0;i这样写
ifor
循环的顺序是这样的:

Perform the initial expression (e.g. assign initial values)
BEGINNING OF 1ST LOOP ITERATION:
Check if the condition is true, and end the loop if it isn't
Do the body of the loop
Increment
BEGINNING OF 2ND LOOP ITERATION:
Check if the condition is true, and end the loop if it isn't
Do the body of the loop
Increment
BEGINNING OF 3RD LOOP ITERATION:
Check if the condition is true, and end the loop if it isn't
Do the body of the loop
Increment
...

依此类推。正如您所看到的,增量是在每次检查之前完成的,而不是像您所想的那样在检查之后完成的。

循环中的语句首先运行,然后递增“i”的值。这就是
i++
函数的工作方式,第一个循环的i=0,依此类推。因此,在第五次迭代中,i将等于4


当我在第五次执行语句后变为5时,它就不再满足条件
i你没有得到5的原因是因为逻辑运算符,条件是
iokay我非常理解这一点,我只是在讨论这个循环中的执行顺序…首先应该运行什么..检查还是增量状态
  for( int i = 0; i<=5; i++) {
    System.out.println(i);
  }   
 0
 1
 2
 3
 4
 5   
Perform the initial expression (e.g. assign initial values)
BEGINNING OF 1ST LOOP ITERATION:
Check if the condition is true, and end the loop if it isn't
Do the body of the loop
Increment
BEGINNING OF 2ND LOOP ITERATION:
Check if the condition is true, and end the loop if it isn't
Do the body of the loop
Increment
BEGINNING OF 3RD LOOP ITERATION:
Check if the condition is true, and end the loop if it isn't
Do the body of the loop
Increment
...
i = 0;
is i < 5? Yes.
[..] i = 5; is i < 5? No. 5 < 5 is false.

for (int i = 0; i <= 5; i++)
{ System.out.println(i); }