File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes tricky for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "tricky for loop " Watch "tricky for loop " New topic
Author

tricky for loop

balajee annamalai
Ranch Hand

Joined: May 09, 2007
Posts: 31
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

Joined: Oct 31, 2007
Posts: 100
use a meaningful subject line

[ April 29, 2008: Message edited by: Ivan Ivanic ]

<a href="http://faq.javaranch.com/java/UseRealWords" target="_blank" rel="nofollow">Use Real Words</a> <a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">!!!Use Code Tags!!!</a> <a href="http://faq.javaranch.com/java/SayThanks" target="_blank" rel="nofollow">Say Thanks</a><br />scjp6
balajee annamalai
Ranch Hand

Joined: May 09, 2007
Posts: 31
OK I will use that from now on but can you help me with this question?
Ivan Ivanic
Ranch Hand

Joined: Oct 31, 2007
Posts: 100
try here
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Nhat Nguyen
Greenhorn

Joined: Jan 09, 2008
Posts: 9
try this:
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
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".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tricky for loop