Php operator `break` doesn't stop while -



Php operator `break` doesn't stop while -

have weird issue, break doesn't break while loop , maintain rotating. logically should break cycle , set output

while ($c++ != 5) { // here curl request, doesn't relevant have removed preg_match("!<.*?>(\s*)[^<>]*?{$to}<!", $resp, $result) ; // echo 'cnt = ' .count($result).'<br>'; if(!count($result)) { $amount = 0; echo 'sleep called'; sleep(4); exit; continue; } else { $amount = trim(@$result[1]); $amount = round($amount + $amount * $exchange_ratio, $precision); echo 'break happen<br>'; break; } }

so output

cnt = 2 break happen cnt = 0 sleep called

so skipped break , maintain rotating. how so?

edit works fine on localhost issue php version?

you must running code multiple times: there sec phone call script, or sec loop around part? @ test code: breaks after break:

$ cat tmp.php

<?php $c = 0; while ($c++ != 5) { if(false) //just emulating { $amount = 0; echo 'sleep called'; sleep(4); exit; continue; //this never called way } else { echo 'break happen<br>'; break; //this indeed breaks out of while } }

$ php tmp.php break happen<br>$

(the $ next prompt, on same line did not set in newline :) )

php

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -