一。break
A. switch语句中,break语句会终止其后语句的执行,退出switch语句。
B. 使一个循环立即结束,也就是说在循环中遇到break语句时,循环立即终止,
程序转到循环体后的第一个语句去继续执行。
A. break语句在循环中使用时,总是与if一起使用,当条件满足(或不满足)
时,负责退出循环。
于结束switch,而不影响循环。
而不是退出外层循环。
二。continue
即遇到continue语句时,不执行循环体中continue后的语句,立即转去判断循环条件是否成立。
3.Continue与break语句的区别:continue只是结束本次循环,而不是终止整个循
环语句的执行,break则是终止整个循环语句的
执行,转到循环语句后的下一条语句去执行。
(1.)
{
三.goto
1.goto语句形式:goto语句是无条件转向语句,其一般形式为:
四.Return
1.return语句形式: return (返回值);
只要遇到return语句,程序就在那一行代码停止执行,执行控制将立刻返回到调用该程序的代码处。
对于返回值类型为void的程序,return关键字单独作为完整的语句使用:
void doSomething(){
}
和
void doSomething(){
}
return 0; //returning a constant integervalue
return x; //returning the value of x(assuming thatx has previously been declared to be an int)
return x+y; //returning the value of theexpression”x+y”(here,we`re assuming that “x+y” evaluates to an intvalue)
return false;
return outcome; //returning the value of variableoutcome (assuming that outcome has previously been declared to beof type Boolean)
boolean isHonorsStudent(){
if(gpa>=3.5) return true; //first returnstatement
else return false; //second returnstatement
}
使用局部boolean型变量result来重写这个程序,该变量捕获最终返回的true/false结果。在程序最末尾用一条return语句返回result变量的值:
boolean isHonorsStudent(){
boolean result = false;
if(gpa>=3.5) result = true;
else result = false;
return result;
}
如上述代码所示,由于已经给result变量赋予初值false,因此在else子句中明确地给它赋值false是不必要的,可以像下面这样简化isHornorsStudent程序:
boolean isHonorsStudent(){
boolean result = false;
if(gpa>=3.5) result = true;
return result;
function cs(n){
if(n==1) { retrun 1; }
if(n==2) { return; }
else { }
}
说明: