Course of Raku / Essentials / Code blocks

Global variables

Let us create a variable before the code block:

my $x = 1;

{
    $x = 42;
    say $x;
}

say $x;

In this case, $x is a global variable (it is located in the global scope), and the program prints 42 twice.

Practice

Complete the quiz that covers the contents of this topic.

Course navigation

Code blocks / Lexical scope   |   Code blocks / Local variables

Translations of this page: EnglishDeutschEspañolItalianoLatviešuNederlandsБългарскиРусскийУкраїнська