Solved

For loop

Posted on 2004-10-19
8
201 Views
Last Modified: 2010-03-31
What does the following for loop mean?

for (NamingEnumeration enu=attr.getAll();enu.hasMore();System.out.println("value: " + enu.next()));

Does it mean,

for (NamingEnumeration enu=attr.getAll();enu.hasMore(); )
    System.out.println("value: " + enu.next());

??
0
Comment
Question by:jtcy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
8 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12346300
yes
0
 
LVL 37

Accepted Solution

by:
zzynx earned 20 total points
ID: 12346323
Like

   for (int i=0; i<5; System.out.println(i++));

means

   for (int i=0; i<5; i++)
        System.out.println(i);
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12346332
Or
        for (int i=0; i<5;)
          System.out.println(i++);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jtcy
ID: 12346361
Why is this fine:

System.out.println("value: " + enu.next()));

but when I do:

String smth = enu.next();, it says incompatible error?, Should I do:

String smth = (String) enu.next();?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12346389
yes
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12346390
next() returns an Object, you have to cast
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12346405
Writing

      System.out.println( "value: " + enu.next() );   // with two closing )'s at the end

is like writing

      System.out.println( "value: " + enu.next().toString() );
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12346500
Thanks
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question