Hacker News new | ask | show | jobs
by deaddodo 2134 days ago
Not sure if you're aware, but you could just write that as:

    int i = 100;
    std::cout << i << std::endl;
    {
        int i = 200;
        std::cout << i << std::endl;
    }
    std::cout << i << std::endl;
And since PyTov is supposed to be C-like, this might be a better example:

    #include <stdio.h>
    
    int main(void) {
        int i = 100;
        printf("%i\n", i);
        {
            int i = 200;
            printf("%i\n", i);
        }
        printf("%i\n", i);
        
        return 0;
    }
Also, the same would occur in C(/C++) if you didn't shadow the variable in the block scope and just called:

    i = 200