How to break if loop in Perl?
How to break "if" checking in Perl? Let's see:
if ($cap) { Net::Pcap::close ($cap); >>> HERE <<< print "\nExit\n"; } I'd like to add another "if" block in this. I'd like to exit from "if" checking in marked place if variable $test would be equal to 1. So, if $test =1, $cap will be closed but text "Exit" won't be displayed. How to do that? "last" doesn't seem to work, because it's designed to use in "while" loops etc., not in "If" statement. Thanks for your help :) |
Yeah, if is not a loop, but a language construct. That aside, the only solution I'm aware of is the ultra-ugly "goto". :)
|
Thx it helped ;) I doesn't think that using goto is bad. I'd say that using it too many times isn't good, but it's not "ugly" as many people says. It's a command like any other, created to be used when necessary - like in this example :)
|
Yeah, well, there essays out there on using goto (and when to or not to).
Which makes me wonder how an optimizing compiler would handle this: (granted, this is C code) Code:
void foo(){ |
Maybe I don't understand the problem but why don't you use another if:
Code:
|
No, he seems to be desiring to break out of multiple areas, as in this code:
Code:
if($cap) |
how about else?
|
Too easy.
Code:
for(;;){ |
How about placing that within [ code] brackets? ;)
|
We're all so stupid. Just do this, as suggested by "John" in another forum:
just put a loop inside the if block: Code:
if ( $expression ) { { |
All times are GMT -5. The time now is 01:24 AM. |