r/learnphp • u/Rex-Havoc • Oct 25 '18
What is a one-armed conditional statement?
I was forced into doing PHP as 'mandatory elective' (god knows how that actually works or how it even makes sense) but out tutor has made it clear that they will not be teaching it to us, its down to us to learn on our own. But her English is appalling and trying to transcribe her assignment sheets is just as much work as the work itself.
We had to create a game and then repeat the same game but using 'a one armed conditional statement' instead. I searched for 'php one armed conditional statement' and all I could find on it was a link to one blank page from another college (http://www.cs.ucc.ie/~dgb/courses/pwd/27/php-one-armed-conditionals1.html) and nothing else that explains it. I tried with out the 'php' in front, thinking it might just be programming lingo but I found even less mentions of it. Is it a real thing? I'm started pulling my hair out over this, I can't find anything about it and she won't answer questions on the assignments.
3
u/slowmode1 Oct 25 '18
Search for "one arm conditional" with the quotes. It is more helpful. Basically, if it is an if statement, it is one-arm. If it has an else, it is two-armed (or more if elseif)
3
u/sveach Oct 25 '18 edited Oct 25 '18
That page isn't actually blank, it just hides all the relevant HTML on page load. If you view source and save the html to your PC and open it in a browser, you can see it.
Based on that page, it's basically an IF statement:
The (one-armed) conditional statement, also called the if-statement:if ( Boolean expression ){zero, one or more statements}
Here's some of the HTML that I pulled from it:
PHP: One-Armed Conditional Statements I
Aims:
to learn how to write some expressions that evaluate to Booleans
to learn the one-armed conditional statement
Comparison operators
Revision of operators: 2 * 3evaluates to 6
A comparison operator compares two values, and evaluates to either true or false
E.g.
2 < 3evaluates to true
2 > 3evaluates to false
These expressions are called Boolean expressions
PHP's comparison operators
OperatorParaphraseExample use
Equals
Identical
Not equal
Not identical
Not equal
Less than
Greater than
Less than or equal to
Greater than or equal to
Using Boolean expressions I
The result of evaluating these expressions can be
stored in a variable
echoed into the output, but strangely...
true is output as '1'
false is output as ''
Class exercise: What's the output of each of the following?
echo 2 < 3;
echo 2 == 3;
echo '2 == 3';
$my_age = 20; $your_age = $my_age;
echo $my_age == $your_age;
echo $my_age < $your_age;
echo $my_age <= $your_age;
$your_age = $your_age + 1; $is_equal = $my_age == $your_age;
echo $is_equal;
$is_less_than = $my_age < $your_age;
echo $is_less_than;
$is_less_than_or_equal_to = $my_age <= $your_age;
echo $is_less_than_or_equal_to;
Using Boolean expressions II: the conditional
The (one-armed) conditional statement, also called the if-statement:if ( Boolean expression ){zero, one or more statements}
If the Boolean expression evaluates to true,
the statements in the curly braces are executed
then execution moves on to statements after the closing curly brace
If the Boolean expression evaluates to false,
the statements in the curly braces are not executed
execution skips to statements after the closing curly brace