I have a code like this:
if (true) {
echo 'one ';
/* I need to jump out of this block */
echo 'two ';
}
echo 'three ';
And here is expected result:
one three
How can I do that?
I have a code like this:
if (true) {
echo 'one ';
/* I need to jump out of this block */
echo 'two ';
}
echo 'three ';
And here is expected result:
one three
How can I do that?
do {
if (true) {
echo 'one ';
break;
echo 'two ';
}
} while(0);
echo 'three ';
Just use the break function.
One can prevent deep nesting full of if-else statements in many cases by breaking
You could just have another if statement. You can only escape out of for, while, and do-while loops using the break statement.
if (true) {
echo 'one ';
if (false) {
echo 'two ';
}
}
echo 'three ';
goto statements in general are just bad practice.
You can't break out of an if block. There has to be a reason why you'd want to break out there otherwise you'd just remove echo two and be done with it. That being the case, just enclose the rest of the code in another condition so that it only executes when you want it to.