Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added mention of if/elsif/else special case
  • Loading branch information
molecules committed Aug 7, 2017
1 parent 5f5a4a6 commit 1608091
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions doc/Language/syntax.pod6
Expand Up @@ -77,15 +77,14 @@ A Perl 6 program is a list of statements, separated by semicolons C<;>.
A semicolon after the final statement (or after the final statement inside a
block) is optional, though it's good form to include it.
A closing curly brace followed by a newline character implies a statement
separator, which is why you don't need to write a semicolon after an C<if>
statement block.
In general, a closing curly brace followed by a newline character implies a statement
separator, which is why you don't need to write a semicolon after an C<if> statement block.
=begin code
if True {
say "Hello";
put "Hello";
}
say "world";
put "world";
=end code
Both semicolons are optional here, but leaving them out increases the chance
Expand All @@ -94,10 +93,31 @@ of syntax errors when adding more lines later.
You do need to include a semicolon between the C<if> block and the say statement if you want them all on one line.
=begin code
if True { say "Hello" }; say "world";
if True { put "Hello" }; put "world";
# ^^^ this ; is required
=end code
As a special case, a series of blocks that are part of the same C<if>/C<elsif>/C<else> (or similar) construct
are treated as a single statement, with an implied statement separator following the last block of the series,
if the last closing curly brace is followed by a newline character.
These three are equivalent:
=begin code
if True { put "Hello" } else { put "Goodbye"}; put "world";
# ^^^ this ; is required
=end code
=begin code
if True { put "Hello" } else { put "Goodbye"} # <- implied statement separator
put "world";
=end code
=begin code
if True { put "Hello" }
else { put "Goodbye"} # <- implied statement separator, just after }
put "world";
=end code
=head2 Comments
Comments are parts of the program text only intended for human readers, and
Expand Down

0 comments on commit 1608091

Please sign in to comment.