Control Structures Flashcards
(39 cards)
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.
When can a break statement end the entire script?
When it’s not in a control loop.
What does continue do?
It’s used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration.
What is the default value for continue or break?
1
What is the default value for continue or break?
1
In a switch statement, what are the limits on the case expression?
It can be any expression that evaluates to an integer or floating-point number or string.
What are the directives you can set using declare?
Ticks and encoding.
What can be given as directive values using declare?
Only literals, not variables or constants.
What is a tick?
e
What is a tick?
An event that occurs for every N low-level tickable statements executed by the parser within the declare block. The value for N is specified using ticks=N within the declare block’s directive section.