?
Solved

For loop

Posted on 2004-10-19
8
Medium Priority
?
205 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 80 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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

770 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