Course of Raku / Essentials / Control flow essentials / Code blocks / Local variables
Quiz — Local variables
1
What does this program print?
my $value = 100;
{
my $value = 1;
$value *= 2;
say $value;
}| 2 | Answer: (: 1, 2, 100, 200 :) | A local variable is used and printed. |
2
What does this program print?
my $value = 100;
{
my $value = 1;
$value *= 2;
}
say $value;| 100 | Answer: (: 1, 2, 100, 200 :) | A local variable is modified, but the global variable is printed. |
3
This program looks almost the same, but there is no my
inside the block. What does it print?
my $value = 100;
{
$value *= 2;
}
say $value;| 200 | Answer: (: 1, 2, 100, 200 :) | Without my, the block has no local variable, so it modifies the same global one. |
Course navigation
← Local variables | Conditional checks →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська