In a loop, I have several conditions and if the condition is not satisfied, I exit out of the loop using last syntax.
while (condition) {
if (possibility 1) {
...
last;
}
if (possibility 2) {
if (possibility 3) {
...
last;
}
...
last;
}
}
After I come out of the loop, I need to know whether I used last to exit, or the condition just did not hold true any more. One way of doing that is to write a if statement that negates all the possibilities.
I am looking for some easier/more elegant way to do this.
Is there some Perl variable that stores the information that we exited out of the loop due to last? Or do I need to maintain such a variable myself?
You pretty much just need to set a flag before you exit
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