Website Development Prices

Search Blog

Saturday, November 14, 2015

Koriscenje iskaza else (Using statement else)

Iskaz if ima i dodatne mogucnosti. Ako je njegov uslov ocenjen kao tacan, dolazi do izvrsenja internog iskaza. Sta ako je iskazan ocenjen kao netacan? Tada mozete upotrebiti iskaz else (klauzula else).

Izraz iskaza if je ocenjen kao netacan, tako da interni iskaz echo "Cena je pristupacna" nece biti izvrsen.

Primer:

<?php

$cenamotora = 2300;

if ($cenamotora > 2500 && $cenamotora < 3000) {
echo "Cena je pristupacna.";
}

else {
echo "Cena je previsoka.";
}


?>

Objasnjenje: posto je uslov if iskaza netacan, izvrsice se interni iskaz u okviru klauzule else. Rezultat ce biti: Cena je previsoka.


Provera da li je student polozio test.

Primer 2:

<?php

$rezultat = 95;

if ($rezultat > 75) {
echo "Polozio sam test.";
}

else {
echo "Nisam polozio test.";
}


?>

Rezultat je: Polozio sam test.


The if statement has additional possibilities. If his condition is assessed as correct, it comes to the execution of the internal statement. What if it is evaluated as incorrect? Then you can use the statement else (else clause).

Term of the if statement is evaluated as incorrect, so that the internal statement echo "The price is affordable," will not be performed.

Example:

<?php


$motobikeprice = 2300;

if ($motobikeprice > 2500 && $motobikeprice < 3000) {
echo "The price is affordable.";
}

else {
echo "The price is too high.";

}

?>

Explanation: since the condition of the if statement is incorrect, internal statement will be performed under the clause else. The result will be: The price is too high.

To verify that the student has passed the test.

Example 2:

<?php

$result = 95;

if ($result > 75) {
echo "I passed the test.";
}

else {
echo "I did not pass the test.";
}


?>

The result is: I passed the test.

No comments:

Post a Comment

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