Q1: |
Must a control structure's test expression result in a Boolean value?
|
A1:
|
Ultimately, yes. However, in the context of a test expression, zero, an undefined variable, or an empty string is converted to false for the purposes of the test. All other values evaluate to true.
|
Q2: |
Must I always surround a code block in a control statement with brackets?
|
A2:
|
If the code you want executed as part of a control structure consists of only a single line, you can omit the brackets. The code examples in this book retain brackets to promote readability. Retaining the brackets for single-line control statements can also help guard against bugs as new lines are added to the block over time.
|
Q3: |
Does this hour cover every kind of loop there is?
|
A3:
|
No. In Hour 7, you'll encounter the foreach statement, which enables you to loop through every element in an array.
|