This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes for each loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "for each loop" Watch "for each loop" New topic
Author

for each loop

akash shrimali
Ranch Hand

Joined: Jul 28, 2010
Posts: 45
how can we perform ternary operation in new enhanced FOR EACH LOOP [ EX ... for(int element:arr) { System.out.println(element); } ]
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Your example does not have a ternary operation and it is not obvious to me what is not obvious to you. Can you elaborate?


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
Hi Akash,

it doesn't seem so clear to me what you want to achieve.

Following your example:



Would you like to give to element variable a value depending on a condition? If that is the question, no is the answer

But you can choose the array or list to navigate through, depending on a conditional operator's result



Tell me if you meant something else.


Bye,
Nicola
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: for each loop
 
Similar Threads
Add condition for-each loop
Iterator vs for loop
printing and returning arrays
for loop problem
Weird issue while populating a table using jquery