Kurso de Raku / Esencoj / Pli pri tipoj / Poziciaj datentipoj / Exercises / Presi serion de nombroj

Solvo: Presi serion de nombroj

There is more than one way to solve the given problem.

Kodo 1

The first solution is more Raku-ish and compact.

my $begin = prompt 'Begin: ';
my $end = prompt 'End: ';

.say for $begin .. $end;

🦋 Find the program in the file series-of-numbers.raku.

Kodo 2

The second possible solution can use the loop statement.

my $begin = prompt 'Begin: ';
my $end = prompt 'End: ';

loop (my $n = $begin; $n <= $end; $n++) {
    say $n;
}

🦋 Find the program in the file series-of-numbers-loop.raku.

As you can see, the first variant is significantly shorter and more expressive.

Diskuto

In the first variant of the program, the postfix form of the for loop is used. In the second program, a loop is chosen.

Eligo

Pass the two numbers in the console and run the program. Both variants produce the same output.

$ raku exercises/positionals/series-of-numbers.raku
Begin: 15
End: 19
15
16
17
18
19

Kursa navigado

Presi serion de nombroj   |   Literumi numeron