@@ -77,15 +77,14 @@ A Perl 6 program is a list of statements, separated by semicolons C<;>.
77
77
A semicolon after the final statement (or after the final statement inside a
78
78
block) is optional, though it's good form to include it.
79
79
80
- A closing curly brace followed by a newline character implies a statement
81
- separator, which is why you don't need to write a semicolon after an C < if >
82
- statement block.
80
+ In general, a closing curly brace followed by a newline character implies a statement
81
+ separator, which is why you don't need to write a semicolon after an C < if > statement block.
83
82
84
83
= begin code
85
84
if True {
86
- say "Hello";
85
+ put "Hello";
87
86
}
88
- say "world";
87
+ put "world";
89
88
= end code
90
89
91
90
Both semicolons are optional here, but leaving them out increases the chance
@@ -94,10 +93,31 @@ of syntax errors when adding more lines later.
94
93
You do need to include a semicolon between the C < if > block and the say statement if you want them all on one line.
95
94
96
95
= begin code
97
- if True { say "Hello" }; say "world";
96
+ if True { put "Hello" }; put "world";
98
97
# ^^^ this ; is required
99
98
= end code
100
99
100
+ As a special case, a series of blocks that are part of the same C < if > /C < elsif > /C < else > (or similar) construct
101
+ are treated as a single statement, with an implied statement separator following the last block of the series,
102
+ if the last closing curly brace is followed by a newline character.
103
+
104
+ These three are equivalent:
105
+ = begin code
106
+ if True { put "Hello" } else { put "Goodbye"}; put "world";
107
+ # ^^^ this ; is required
108
+ = end code
109
+
110
+ = begin code
111
+ if True { put "Hello" } else { put "Goodbye"} # <- implied statement separator
112
+ put "world";
113
+ = end code
114
+
115
+ = begin code
116
+ if True { put "Hello" }
117
+ else { put "Goodbye"} # <- implied statement separator, just after }
118
+ put "world";
119
+ = end code
120
+
101
121
= head2 Comments
102
122
103
123
Comments are parts of the program text only intended for human readers, and
0 commit comments