Skip to content

Commit ae8d174

Browse files
authored
Added mention of if/elsif/else special case
Does this look okay? Inspired by brian d foy's question (https://stackoverflow.com/questions/45520479/is-perl-6s-uncuddled-else-a-special-case-for-statement-separation).
1 parent 5f5a4a6 commit ae8d174

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

doc/Language/syntax.pod6

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,14 @@ A Perl 6 program is a list of statements, separated by semicolons C<;>.
7777
A semicolon after the final statement (or after the final statement inside a
7878
block) is optional, though it's good form to include it.
7979
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.
8382
8483
=begin code
8584
if True {
86-
say "Hello";
85+
put "Hello";
8786
}
88-
say "world";
87+
put "world";
8988
=end code
9089
9190
Both semicolons are optional here, but leaving them out increases the chance
@@ -94,10 +93,31 @@ of syntax errors when adding more lines later.
9493
You do need to include a semicolon between the C<if> block and the say statement if you want them all on one line.
9594
9695
=begin code
97-
if True { say "Hello" }; say "world";
96+
if True { put "Hello" }; put "world";
9897
# ^^^ this ; is required
9998
=end code
10099
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+
101121
=head2 Comments
102122
103123
Comments are parts of the program text only intended for human readers, and

0 commit comments

Comments
 (0)