Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statement Vs Block Level variable

 
Chandra shekar M
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In java Statement level variable means

for(int i=0;i<10;i++) "i" as in this for loop. Block level variable means some thing like { int j; } which is inside the braces.

Is this the difference between Block and Statement level variable in java

Thanks
Chandra
 
Greg Brannon
Bartender
Posts: 563
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've not heard the term "statement-" or "block-level variables" in Java, but I'm always learning.

Here is the authoritative discussion of variables in Java. I believe that 'i' and 'j' in both of your examples would be called 'local variables.' The 'i' is local to the for loop; the 'j' is local to the block of code in which it is contained. Neither are visible outside their respective localities.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50225
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Language Specification is more authorative than the tutorials, and here there is no mention of block- or statement-level variables. For the purposes of that definition, a for statement and a block are regarded as the same, so you cannot distinguish block or statement variables.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic