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

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -