java 中 while里有个if 想跳过本次循环继续,需要再if里写什么?

2025-03-24 01:25:37
推荐回答(3个)
回答1:

写continue;
continue是表示结束本次循环,继续下一次循环。
break表示结束整个循环,继续执行循环后面的代码。

回答2:

/*
 * for me, this is a time, in which never write java code.
 * e-mail:qinchuanqing918@sina.com
 * data:2015/5/22
 * author:qcq
 * */
package com.nokia;


public class MapIter {

public static void main(String[] args) {
int counter = 0;
while(counter++ <= 100){
if (0 == counter % 2){
continue;
} else {
System.out.print(counter + ",");
}
}
}

}

回答3:

写continue