Website Development Prices

Website Development Prices

Thursday, January 28, 2016

Preskakanje iteracija-iskaz continue (Skipping iteration-statement continue)

Iskaz continue mozete koristiti unutar petlje da preskocite izvrsenje tekuce iteracije i da nastavite naredbu iteraciju.

Primer: koristimo iskaz continue da izbegnemo deljenje sa nulom, sto je beskonacno i dovodi do greske.

<?php

for ($vrednost = -2; $vrednost < 2 ; $vrednost++) {
if ($vrednost == 0) {
continue;
}
echo "1/$vrednost = ", 1 / $vrednost, "<br>";




?>

Rezultat:

1/-2 = -0.5
1/-1 = -1
1/1 = 1


The statement continue you can use in the loop to skip the execution of the current iteration and continue to the next iteration.

Example: we are using the statement continue to avoid division by zero, which is infinite and leads to error.

<?php

for ($value = -2; $value < 2 ; $value++) {
if ($value == 0) {
continue;
}
echo "1/$value = ", 1 / $value, "<br>";



?>

Result:

1/-2 = -0.5
1/-1 = -1
1/1 = 1

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.