Save me from raptor death - is there any better way to handle this kind of structure?
while(condition) {
$this->phase1();
$this->phase2();
$this->phase3();
$this->phase4();
}
Throughout either one of those methods, the condition could be met. IMMEDIATELY after the condition is met, the loop MUST exit. If I could call break;
inside of phase2();
for example, I wouldn't need a goto statement (but of course, that would throw an error).
The goto statement can be used to alter the normal flow of control in a program. This statement causes the program to jump to a specified label.
"The GOTO statement is generally considered to be a poor programming practice that leads to unwieldy programs. Its use should be avoided."
From the early days of programming (i.e. assembler programming) the replacement for goto directives is so-called structured programming. This means using if-then-else statements, for- and while-loops, switch statements, break and continue, etc.
Return a boolean to execute each stage until successful.
while (condition) {
if ($this->phase1() || $this->phase2() || $this->phase3() || $this->phase4()) {
// Success!
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With