Infinite for-loop in perl -
Can anyone tell me, why do I get infinite loop? Although it will not be an infinite loop with a loop.
#! Use / usr / bin / perl strict; Use warnings; My $ i; My $ ipv4 = 0; My $ ipv6 = 0; ($ I = 1; $ i> $; + i ++) {print "$ i \ n"; If ($ ipv4 eq $ ipv6) {$ i = 0; }}
The third description for the loop $ i ++
Is executed at the end of each block and the second statement $ i> 0
is executed in the beginning.
(You are using string comparator eq
instead of a numeric one ==
.)
Whatever you , It's equal to:
$ i = 1; While ($ i> gt;) {print "$ i \ n"; If ($ ipv4 == $ ipv6) {$ i = 0; } $ I ++; }
You should use a last
statement instead:
$ i = 1; While (1) {print "$ i \ n"; If ($ ipv4 == $ ipv6) {last; } $ I ++; }
Comments
Post a Comment