Can't really understand the logic


#1

i tried this and it works fine my only question is

i get how that bit of code works but i can't really understand the logic

here is what i edited







<?php
$a = "c";
if ($a=="a") {
echo "too cold";
} elseif ($a=="b") {
echo "too hot";
} else {
echo "just right";
}
?>


Unknown error@ Control flow switch 1.Glance at he past
#2

The if statement is commonly referred to as a conditional branch. If condition flow this way; otherwise...

    /*
    if condition take this action

    continue flow
    */

Alternately we can take one of two actions...

    /*
    if condition take this action

    else take this action

    continue flow
    */

Then we get to multiway branches

    /*
    if condition_a take this action

    elseif condition_b take this action
     ...
    elseif condition_n take this action

    else take this action

    continue flow
    */

#3

i get it now mostly had to do with what i was putting down

$a =10

if ($a =10 ){
echo "t";
}

elseif ($a!=10){
echo "f";
}

else{

// not need it in the condition i set
}

does this make sense?


#4

This is an else not an elseif. It is either ==10 or it is not.

Consider something along these lines (pseudo code, not PHP syntax)

a = (a random signed float)
if  a < 0 print 'negative'
elseif a > 0 print 'positive'
else print 'zero'

Consider also,

bill = items * price
if bill > some_minimum discount by 10%
else if bill > some_lower_min discount by 5%
else no discount

The else in the above may not be needed, but I cannot remember if PHP can be written without it. Something to look into.