Update page 'Aer v1.0 Specification'
@@ -266,7 +266,7 @@ It means that $a and $b point to the same content.
|
||||
#### 5.14.2. Return Reference
|
||||
When a function returns a reference, it returns an implicit pointer to its return value. This way, a function can be used on the left side of an assignment statement.
|
||||
|
||||
int $table[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
|
||||
int[] $table = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
|
||||
|
||||
int &refFunc(int $i) {
|
||||
return $table[$i]; // returns a reference to the ith element
|
||||
@@ -453,7 +453,7 @@ In above example, first the iteration is executed and then the truth expression
|
||||
### 7.5. For Loop
|
||||
The for loop does the same thing as the while loop. Only it puts all three phases, initialization, testing and updating into one place, between the round brackets. It is mainly used when the number of iteration is know before entering the loop.
|
||||
|
||||
string $days[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
|
||||
string[] $days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
|
||||
"Saturday", "Sunday" };
|
||||
int $len = sizeof($days);
|
||||
|
||||
@@ -466,7 +466,7 @@ The three phases are divided by semicolons. First, the $i counter is initiated.
|
||||
### 7.6. Foreach Loop
|
||||
The foreach construct simplifies traversing over collections of data. It has no explicit counter. The foreach statement goes through the array one by one and the current value is copied to a variable defined in the construct. In Aer, it can be used to traverse over an array.
|
||||
|
||||
string $days[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
|
||||
string[] $days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
|
||||
"Saturday", "Sunday" };
|
||||
string $day;
|
||||
foreach ($days as $day) {
|
||||
@@ -477,7 +477,7 @@ The usage of the foreach statement is straightforward. The $days is the array th
|
||||
|
||||
There is another syntax of the foreach statement. Below form will additionally assign the current element's key to the $key variable on each iteration.
|
||||
|
||||
string $benelux[] = { 'be' => 'Belgium', 'lu' => 'Luxembourgh', 'nl' => 'Netherlands' };
|
||||
string[] $benelux = { 'be' => 'Belgium', 'lu' => 'Luxembourgh', 'nl' => 'Netherlands' };
|
||||
string $key, $value;
|
||||
foreach ($benelux as (string) $key => $value) {
|
||||
print("$key is $value\n");
|
||||
|
||||
Reference in New Issue
Block a user