Website Development Prices

Search Blog

Thursday, November 19, 2015

Koriscenje iskaza elseif (Using statement elseif)

Za proveru drugih uslova mozete koristiti iskaz elseif. Iskaz elseif se koristi da bi u okviru istog iskaza if proveravali vise uslova.

Ako zelite zaposlenima da saopstite visinu povisice na osnovu ucinka. Ako biste koristili samo iskaze if i else, zaposlenima biste mogli da saopstite samo da li su dobili povisicu ili ne.

Primer:

<?php

$zalaganje = 7;
if ($zalaganje > 10) {
echo "Dobili ste povisicu.";
}

else {
echo "Niste dobili povisicu.";
}


?>

Ovaj primer sacuvajte kao iskaz-elseif.php.


Rezultat: Niste dobili povisicu.

Iskaz elseif se izvrsava samo ako je glavni iskaz ocenjen kao netacan, ali razlikuje se od iskaza else, po tome sto mozete ukljucite novi uslov koji ce se proveravati.

Ako zelite da proverite koliko je neki zaposleni dobio povisicu.

Primer 2: 

<?php

$zalaganje = 7;

if ($zalaganje > 9) {
echo "Dobili ste 1000 dinara povisicu.";
}

if ($zalaganje > 8) {
echo "Dobili ste 800 dinara povisicu.";
}

if ($zalaganje > 7) {
echo "Dobili ste 700 dinara povisicu.";
}

if ($zalaganje > 6) {
echo "Dobili ste 600 dinara povisicu.";
}

else {
echo "Niste dobili povisicu.";

}

?>

Rezultat: Dobili ste 600 dinara povisicu.



To check other conditions you can use elseif statement. The statement elseif is used to check more conditions within the same statement
.
If you want to tell employees how much raise they got. If you use only the statements if and else, you could tell them only if they did get a raise or not.

Example:

<?php

$effort = 7;
if ($effort > 10) {
echo "You got a raise.";
}

else {
echo "You did not get a raise.";
}


?>

Save this example like statement-elseif.php.

Result: You did not get a raise.

The statement elseif is executed only if the main statement is evaluated as incorrect, but differs from the statement else, in that, it can turn a new condition to be checked.

If you want to check how much some employee got a raise.

Example 2:

<?php

$effort = 7;

if ($effort > 9) {
echo "You got a $100 raise.";
}

if ($effort > 8) {
echo "You got a $80 raise.";
}

if ($effort > 7) {
echo "You got a $70 raise.";
}

if ($effort > 6) {
echo "You got a $60 raise.";
}

else {
echo "You did not get a raise.";
}


?>


Result: You got 60$ raise.

No comments:

Post a Comment

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