Solved

For loop

Posted on 2004-10-19
8
199 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate example for saving data 19 107
Chrome and Firefox Java 5 86
Problem to Alipay 10 92
Fast way to search item into Java Array (Rhino compatible) 2 46
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

738 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