[英]How to use a while loop condition without initializing a boolean twice?
What is the best way to simply this expression so that I don't have to set colFinished twice? 简化此表达式的最佳方法是什么,这样我就不必两次设置colFinished了? (colFinished has to be reset to false in each run of the outer loop)
(在外循环的每次运行中,colFinished必须重置为false)
boolean colFinished = false;
for (int c = 0; c < SIZE; c += 1) {
colFinished = false;
while (!colFinished) {
for (int r = 1; r < SIZE; r++) {
...
If you have no use of colFinished
outside the for
loop, try : 如果在
for
循环外没有使用colFinished
,请尝试:
for (int c = 0; c < SIZE; c += 1) {
boolean colFinished = false;
...............
Else I think there is no other way. 否则,我认为别无选择。
You can declare your variable inside the first for-loop: 您可以在第一个for循环中声明变量:
for (int c = 0; c < SIZE; c += 1) {
boolean colFinished = false;
while (!colFinished) {
for (int r = 1; r < SIZE; r++) {
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.