Quick actions

cmd+k|ctrl+k

Navigation

Languages

For

Snippet info

Language

Raku

Visibility

public

Author

kaspik99

Created

2017-12-06T16:38:16Z

Updated

2018-01-12T17:27:37Z

my @a = < alpha beta gamma delta >;
for @a {
    say $_;
}

say '';
.say for @a;

say '';
for @a -> $x {
    say $x;
}

say '';
for @a -> $x, $y {
    say "$x $y";
}

say '';
my %h = alpha => 'a', beta => 'b', 
        gamma => 'c', delta => 'd';

for %h.kv -> $greek, $latin {
    say "$greek=$latin";
}

say '';
for 1..5 -> Int $i {
    say $i;
}

say '';
my @itemlist = (
    { book => {author => 'Пушкин А. С.', title => 'Сказка о попе и ...'}, count => 1, tags => qw|Поп Балда попадья черти| },
    { book => {author => 'Гоголь Н. В.', title => 'Ночь перед ...'}, count => 1, tags => qw|Вакула Солоха Дьяк Чёрт| },
);

for @itemlist -> % (:%book (Str:D :$title, Str:D :$author), Int :$count,
                    :@tags ($first-tag, *@other-tags))
{
    say "$title, $author, $count, $first-tag, @other-tags[]";
}

# see: https://docs.perl6.org/language/phasers#Loop_Phasers
say '';
my @a2 = 1..Inf;
my $s = '-' x 10;
for @a2[^5] -> Int $i {
    FIRST { say "Поехали!\n{$s}"; }
    say $i;
    NEXT { say $s; }
    LAST { say 'Полёт завершён!'; }
}

say '';
my @q = 1,3...Inf;
for @q {
    say $_;
    # You can...
    next if $_ == 3; # Skip to the next iteration (`continue` in C-like languages).
    redo if $_ == 4; # Re-do the iteration, keeping the same topic variable (`$_`).
    last if $_ > 5; # Or break out of a loop (like `break` in C-like languages).
}

say '';
my @foo = 1..3;
for @foo <-> $_ { $_++ }
say @foo; # [2, 3, 4]

say '';
my @list = 1, 2, 3, 4;
for @list -> $a, $b = 'N/A', $c = 'N/A' {
    say "$a $b $c"
}
# 1 2 3
# 4 N/A N/A



INFO