救我脱离猛禽死亡 - 有没有更好的方法来处理这种结构?
while(condition) {
$this->phase1();
$this->phase2();
$this->phase3();
$this->phase4();
}
Run Code Online (Sandbox Code Playgroud)
在这些方法中的任何一种中,都可以满足条件.在条件满足后立即,循环必须退出.例如,如果我可以调用break;内部phase2();,我就不需要goto语句(当然,这会引发错误).
Bra*_*och 11
返回一个布尔值来执行每个阶段直到成功.
while (condition) {
if ($this->phase1() || $this->phase2() || $this->phase3() || $this->phase4()) {
// Success!
}
}
Run Code Online (Sandbox Code Playgroud)