Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Corrected indentation of some code examples
  • Loading branch information
Jan-Olof Hendig committed Aug 31, 2016
1 parent 06e4986 commit 07f48e2
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions doc/Language/control.pod6
Expand Up @@ -44,7 +44,7 @@ L<elsewhere|/language/functions#Blocks_and_Lambdas>. For now it is just
important to understand when blocks run and when they do not:
=for code :skip-test
say "We get here"; { say "then here." }; { say "not here"; 0; } or die;
say "We get here"; { say "then here." }; { say "not here"; 0; } or die;
In the above example, after running the first statement, the first block stands
alone as a second statement, so we run the statement inside it. The second
Expand Down Expand Up @@ -90,8 +90,8 @@ The simplest way to run a block where it cannot be a stand-alone statement
is by writing C<do> before it:
=for code :skip-test
# This dies half of the time
do { say "Heads I win, tails I die."; Bool.pick } or die; say "I win.";
# This dies half of the time
do { say "Heads I win, tails I die."; Bool.pick } or die; say "I win.";
Note that you need a space between the do and the block.
Expand All @@ -116,9 +116,9 @@ but this is mainly just useful for avoiding the syntactical need to
parenthesize a statement if it is the last thing in an expression:
=for code :skip-test
3, do if 1 { 2 } ; #-> 3, 2
3, (if 1 { 2 }) ; #-> 3, 2
3, if 1 { 2 } ; # Syntax error
3, do if 1 { 2 } ; #-> 3, 2
3, (if 1 { 2 }) ; #-> 3, 2
3, if 1 { 2 } ; # Syntax error
...which brings us to C<if>.
Expand All @@ -132,10 +132,10 @@ Unlike some languages the condition does not have to be parenthesized,
instead the C<{> and C<}> around the block are mandatory:
=for code :skip-test
if 1 { "1 is true".say } ; # says "1 is true"
if 1 "1 is true".say ; # syntax error, missing block
if 0 { "0 is true".say } ; # does not say anything, because 0 is false
if 42.say and 0 { 43.say }; # says "42" but does not say "43"
if 1 { "1 is true".say } ; # says "1 is true"
if 1 "1 is true".say ; # syntax error, missing block
if 0 { "0 is true".say } ; # does not say anything, because 0 is false
if 42.say and 0 { 43.say }; # says "42" but does not say "43"
There is also a form of C<if> called a "statement modifier" form. In this
case, the if and then the condition come after the code you want to run
Expand Down Expand Up @@ -179,16 +179,16 @@ with C<else> to provide an alternative block to run when the conditional
expression is false:
=for code :skip-test
if 0 { say "no" } else { say "yes" } ; # says "yes"
if 0 { say "no" } else{ say "yes" } ; # syntax error, space is required
if 0 { say "no" } else { say "yes" } ; # says "yes"
if 0 { say "no" } else{ say "yes" } ; # syntax error, space is required
The C<else> cannot be separated from the conditional statement by a
semicolon, but as a special case, it is OK to have a newline.
=for code :skip-test
if 0 { say "no" }; else { say "yes" } ; # syntax error
if 0 { say "no" }
else { say "yes" } ; # says "yes"
if 0 { say "no" }; else { say "yes" } ; # syntax error
if 0 { say "no" }
else { say "yes" } ; # says "yes"
Additional conditions may be sandwiched between the C<if> and the
C<else> using C<elsif>. An extra condition will only be evaluated
Expand All @@ -209,14 +209,14 @@ instead of an C<else> if you want.
You cannot use the statement modifier form with C<else> or C<elsif>:
=for code :skip-test
42.say if 0 else { 43.say } # syntax error
42.say if 0 else { 43.say } # syntax error
All the same rules for semicolons and newlines apply, consistently
=for code :skip-test
if 0 { say 0 }; elsif 1 { say 1 } else { say "how?" } ; # syntax error
if 0 { say 0 } elsif 1 { say 1 }; else { say "how?" } ; # syntax error
if 0 { say 0 } elsif 1 { say 1 } else { say "how?" } ; # says "1"
if 0 { say 0 }; elsif 1 { say 1 } else { say "how?" } ; # syntax error
if 0 { say 0 } elsif 1 { say 1 }; else { say "how?" } ; # syntax error
if 0 { say 0 } elsif 1 { say 1 } else { say "how?" } ; # says "1"
if 0 { say 0 } elsif 1 { say 1 }
else { say "how?" } ; # says "1"
Expand Down Expand Up @@ -255,9 +255,9 @@ with C<unless> because that ends up getting confusing. Other than those
two differences C<unless> works the same as L<#if>:
=for code :skip-test
unless 1 { "1 is false".say } ; # does not say anything, since 1 is true
unless 1 "1 is false".say ; # syntax error, missing block
unless 0 { "0 is false".say } ; # says "0 is false"
unless 1 { "1 is false".say } ; # does not say anything, since 1 is true
unless 1 "1 is false".say ; # syntax error, missing block
unless 0 { "0 is false".say } ; # says "0 is false"
unless 42.say and 1 { 43.say } ; # says "42" but does not say "43"
43.say unless 42.say and 0; # says "42" and then says "43"
Expand Down Expand Up @@ -335,7 +335,7 @@ list when they are needed, so to read a file line by line, you could
use:
=for code :skip-test
for $*IN.lines -> $line { .say }
for $*IN.lines -> $line { .say }
Iteration variables are always lexical, so you don't need to use C<my> to give
them the appropriate scope. Also, they are read-only aliases. If you need them
Expand Down Expand Up @@ -490,11 +490,11 @@ block, skipping the rest of the statements, and resuming after the block.
This prevents the C<when> or C<default> from exiting the outer block.
=for code :skip-test
default {
proceed;
"This never says".say
}
"This says".say;
default {
proceed;
"This never says".say
}
"This says".say;
This is most often used to enter multiple C<when> blocks. C<proceed> will
resume matching after a successful match, like so:
Expand Down Expand Up @@ -589,7 +589,7 @@ iteration.
The infinite loop does not require parentheses.
=for code :skip-test
loop { say 'forever' }
loop { say 'forever' }
The C<loop> statement may be used to produce values from the result of each
run of the attached block if it appears in lists:
Expand Down

0 comments on commit 07f48e2

Please sign in to comment.