Something that might be helpful is using computers. Files created on the school computer in the classroom don't exist anywhere else. The file can be copied somewhere else, just like passing it back from a function copies the data, not the variable, to the caller.
To demonstrate inner block access to variables at higher level you can use Google Drive, or something similar. A file on Google Drive can be edited using the web interface, so the local computer has access to the data. Still, the data belongs to Google Drive, so any other computer can also access it and change it. Just like all the loops and blocks in the current subroutine have access to data that belongs to the routine, or anything that is has access to from an even higher level. (The last part might be language dependent, and not apply in the language you utilize, and can be dropped.)
A second option is just to use the directory structure of the computer itself. Creating
/home/mine/Documents/computer_class/project_1/notes.txt will show
file not found if you try to access
/home/mine/Documents/computer_class/notes.txt. [Or for Windows
C:\Users\mine\Documents\Computer Class\Project 1\notes.txt can't be edited using
One thing to bear in mind is that not all languages enforce variables to be scoped at that granular of a level, or at all. In addition, how that scope is enforced, or implemented, can also be language dependent. If the language in use has been dissected by the class, then using its internal process can explain why it happens in that case.
Unless the students will always be using that language, even after school, I think it's important to also make them aware that those rules may, or may not, apply, and that when they don't apply side effects can become an issue. In some cases the value isn't
undefined, as in non-existent, rather it can be
undetermined, as in something is there, but not sure what.