Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 67 lines (57 sloc) 1.216 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
use v6;

use Test;

plan 12;

# L<S04/The Relationship of Blocks and Declarations/"no implicit blocks" around
# "standard control structures">
{
    my $y;
    if (my $x = 2) == 2 {
        $y = $x + 3;
    }
    is $x, 2, '$x assigned in if\'s condition';
    is $y, 5, '$y assigned in if\'s body';
}

{
    my $y;
    unless (my $x = 2) != 2 {
        $y = $x + 3;
    }
    is $x, 2, '$x assigned in unless\'s condition';
    is $y, 5, '$y assigned in unless\'s body';
}

{
    my $y;
    given my $x = 2 {
        when 2 { $y = $x + 3; }
    }
    is $x, 2, '$x assigned in given\'s condition';
    is $y, 5, '$y assigned in given\'s body';
}

{
    my $y;
    while my $x = 2 {
        $y = $x + 3;
        last;
    }
    is $x, 2, '$x assigned in while\'s condition';
    is $y, 5, '$y assigned in while\'s body';
}

{
    my $y;
    for my @a = 1..3 {
        $y = @a[1] + 3;
        last;
    }
    is ~@a, '1 2 3', '@a assigned in for\'s condition';
    is $y, 5, '$y assigned in for\'s body';
}

{
    my $y;
    loop (my $x = 2; $x < 10; $x++) {
        $y = $x + 3;
        last;
    }
    is $x, 2, '$x assigned in loop\'s condition';
    is $y, 5, '$y assigned in loop\'s body';
}

# vim: ft=perl6
Something went wrong with that request. Please try again.