Control Structures Flashcards
What is a statement-group?
A group of statements encapsulated with curly braces, that itself is also a statement.
When can using ‘else if’ instead of ‘elsif’ be problematic?
When using a colon to define your if/elseif conditions. It will fail with a parse error.
What is the alternative syntax for control structures?
For if, while, for, foreach, and switch, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.
Any output (including whitespace) between a switch statement and the first case…
…will result in a syntax error.
Any output (including whitespace) between a switch statement and the first case…
…will result in a syntax error.
Any output (including whitespace) between a switch statement and the first case…
…will result in a syntax error.
What happens when an expression in a for loop is empty?
It’s skipped. expr2 being empty means the loop should be run indefinitely.
What happens when multiple expressions separated by commas are in a for loop?
In expr2, all expressions separated by a comma are evaluated but the result is taken from the last part.
What happens when multiple expressions separated by commas are in a for loop?
In expr2, all expressions separated by a comma are evaluated but the result is taken from the last part.
What does foreach work on?
Only on arrays and objects. When you try to use it on a variable with a different data type, or on an unitialized variable, it will issue an error.
Why don’t you need to call reset() before a foreach loop?
When foreach first starts executing, the internal array pointer is automatically reset to the first element of the array.
How can you directly modify array elements within a foreach loop?
Precede $value with &, and the value will be assigned by reference. Like this:
How can you directly modify array elements within a foreach loop?
Precede $value with &, and the value will be assigned by reference. Like this:
Is ‘break 0’ or ‘continue 0’ valid now?
No.
Can you pass in variables to break or continue: break $num?
No.