• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

tricky for loop

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try here
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this:
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
reply
    Bookmark Topic Watch Topic
  • New Topic