Skip to main content
8 votes

How to illustrate scope problem when creating variables inside `if` statements in Java

I like to use an analogy from Finding Nemo. I tell them their programming language has the same problem Dory has - short-term memory loss. When a variable is declared within a block, Java will ...
Matthew Fahrenbacher's user avatar
6 votes

How to illustrate scope problem when creating variables inside `if` statements in Java

I explain this with a saying: What happens in the block stays in the block Now, this isn't exactly how it works, but the idea is that the students remember that what they create in a block, is ...
ItamarG3's user avatar
  • 6,312
5 votes

How to illustrate scope problem when creating variables inside `if` statements in Java

I teach my students a bit about the stack as part of the very first lesson of the year. As a result, they are aware coming in that primitive variables are stored next to one another in the stack ...
Ben I.'s user avatar
  • 34.3k
4 votes

First Time teaching 6th & 7th grade computer science

Concur with @Ben about HTML5 (see disclaimer, below). Recommend investigating the Computer Science Field Guide (don't be distracted by the TLD, the Curriculum Guides include AP-CSP. (and New Zealand ...
d-n's user avatar
  • 137
3 votes

How to illustrate scope problem when creating variables inside `if` statements in Java

Java, like C/C++ has block scope. When you create a variable in a block, the stack pointer moves to make room for it. When the block ends, the stack pointer moves back. This makes the variable ...
ncmathsadist's user avatar
  • 2,359
3 votes

How to illustrate scope problem when creating variables inside `if` statements in Java

You should be able to copy/paste block of codes that does not use other variables. But in your examples what if you want to copy/paste that to a code that already declared x? It would not work ...
CodesInTheDark's user avatar
2 votes

How to illustrate scope problem when creating variables inside `if` statements in Java

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 ...
Gypsy Spellweaver's user avatar
2 votes

First Time teaching 6th & 7th grade computer science

I have a few thoughts: Scratch is wonderful, and very appropriate to that age group. TinkerCAD is another great alternative. HTML/CSS is fine as an entree into JavaScript for front end web ...
Ben I.'s user avatar
  • 34.3k
1 vote

How to illustrate scope problem when creating variables inside `if` statements in Java

Another benefit of block-level scope is that because variables defined in a block go out of scope at the end of that block, their values are then eligible for garbage collection (assuming no other ...
Kevin Workman's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible