Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tricky for loop

 
balajee annamalai
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to know why option (a) is working and not option (b) what is the difference?



Can any one please expain this?
[ April 30, 2008: Message edited by: balajee annamalai ]
 
Ivan Ivanic
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use a meaningful subject line

[ April 29, 2008: Message edited by: Ivan Ivanic ]
 
balajee annamalai
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I will use that from now on but can you help me with this question?
 
Ivan Ivanic
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try here
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by balajee annamalai:
OK I will use that from now on but can you help me with this question?


You can always go back and edit your subject line by clicking on the icon in the top post of your thread.
 
Nhat Nguyen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this:
 
Guido Sautter
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by balajee annamalai:
I need to know why option (a) is working and not option (b) what is the difference?



Can any one please expain this?


The difference is that in variant b you have a single line as the body of the for loop, and such a single line body may not declare variables. This is allowed only inside a block enclosed in curly brackets, as in variant a. For such an enclosed block, it does not matter if its only line declares a variable, at least not in terms of a compiler error. You might get a warning, though: "the local variable j is never read".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic