2014-02-06 47 views
0

我的PHP服務器使用PHP版本5.2.17和PHP goto不工作。替代「goto」在PHP

如何做到沒有「goto」的循環?

while ($i <= $dadosrolados) { 
    a: 
    $j = rand(1,10); 
    if (isset($um) and $j == 1) { 
     goto a; 
    } 
    else { 
     $dados["Dado ".$i] = "$j"; 
    } 
    $i++; 
} 
+0

你可以把'$ i ++'的東西,這似乎裏面像它會給你同樣的結果 – StephenTG

+4

http://www.php.net/manual/en/control-structures。 continue.php – Dave

+0

按照Dave的說法使用'continue',爲了上帝的愛,儘量不要使用'goto'。永遠。 [認真](http://xkcd.com/292/)。 – Wrikken

回答

0
do { 
    $j = rand(1,10); 
} while (isset($um) and $j == 1);