1 java loops for-loop while-loop
我想将此for循环更改为while语句:
for (int x = 0; x < items.size(); x++) {...}
Run Code Online (Sandbox Code Playgroud)
我试过了:
int x = 0;
while(x<items.size()){
x++;
...
}
Run Code Online (Sandbox Code Playgroud)
但它不会起作用.
它应该是
int x = 0;
while(x<items.size()){
...
x++;
}
Run Code Online (Sandbox Code Playgroud)
在循环结束时使用x ++(因为在for循环中,增量部分仅在程序控制到达结束括号后执行),否则一切看起来都正常.它应该工作.