在java中要使用continue,break和return作为循环和跳转语句。
标准格式:
break [label]:用来从switch语句,循环中跳出。
continue[label]:跳过循环体的剩余语句,开始新一轮循环。
return ():返回一个常量或方法。
break和continue后都可加参数。不加参数的用法同上,含有参数的用法应该是这样:
带标签的continue的作用是结束当前循环,并去执行标签所处的循环;
带标签的break的作用是从标签指定的语句块跳出。
sample code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testcode;
/**
*
* @author firedom
*/
public class TestCode {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int i = 0;
state:
while(true){
i += 1;
if(i >= 100){
System.out.println(i);
break;
}
System.out.println("continue");
continue state;
}
}
}