php的多分支控制
php的多分支控制
====php的多分支控制====
###if方式实现多分支控制
if(runStep(1)){
if(runStep(2)){
if(runStep(3)){
#allstepsaresuccess!!
}else{
#step03isfailed!
}
}else{
#step03isfailed!
}
}else{
#step03isfailed!
}
#someotherssteps
###if方式2实现多分支控制
$r=0;
if(runStep(1))
if(runStep(2))
if(runStep(3))
else$r=3;
else$r=2;
else$r=1;
if($r){
#step$risfailed!
returnfalse;
}
#someotherssteps
###do..while(false)方式2实现多分支控制
do{
if(!runStep(1))#step01isfailed!
break;
if(!runStep(2))#step02isfailed!
break;
if(!runStep(3))#step03isfailed!
break;
#allstepsaresuccess!!
}while(false);
#someotherssteps
###switch(true)方式2实现多分支控制
switch(true){
case!runStep(1):
#step01isfailed!
break;
case!runStep(2):
#step02isfailed!
break;
case!runStep(3):
#step03isfailed!
break;
default:
#allstepsaresuccess!!
break;
}
#someotherssteps
###try..catch方式实现
try{
if(!runStep(1))thrownewSomeError(1);#step01isfailed!
if(!runStep(2))thrownewSomeError(2);#step02isfailed!
if(!runStep(3))thrownewSomeError(3);#step01isfailed!
#allstepsaresuccess!!
}catch(SomeError$ex){
#step$exisfailed!
returnfalse;
}
#someotherssteps