Loops and Branches Flashcards
What are the comparison operators?
==
!=
>
>=
- $a is not equal to $b after type juggling.
- An integer less than, equal to, or greater than zero when $a is respectively less than, equal to, or greater than $b. Available as of PHP 7.
Null - The first operand from left to right that exists and is not NULL. NULL if no values are defined and not NULL. Available as of PHP 7.
What does ‘default’ do in a switch statement?
The default action executes if none of the other switch statements are true.
What happens if you do not include ‘break’ into your switch cases?
It will continue executing the statements of following cases.
What is the syntax of a “for” loop?
for( initialization; condition; increment ){ // block of commands; }
What is the difference between “while” and “do while” loops?
The “do while” loop will always execute at least one time because the condition comes after the command block, whereas the “while” loop condition occurs before the command block.
What are the ideal use cases for “for” loops and “while” loops?
The “while” loop is most useful when you have an unknown or variable number of items to loop through. The “for” loop is most useful when you have a fixed number.
What is the syntax of a “foreach” loop?
foreach($array as $key => value){ // block of commands }
What is a “foreach” loop?
It is made specifically for use with arrays, to iterate through an array from beginning to end.
What is the “continue” command?
“Continue” is used to skip a block of code but continue inside a loop.
What is the “goto” command?
“Goto” is used to force a jump to a specific place in the program.