• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Difficulty understanding this for loop...

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I'm working with JavaSound and MIDI right now, and I've got the following conditional which I'm trying to understand:



Now the part which I mainly don't understand is the "Transmitter tx : transmitters" part. What does that colon do?

Here's the 'full' code:



Thank you kindly.
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's what is called the 'enhanced for loop' or the 'for each' loop.

transmitters is some kind of collection that holds Transmitter objects. so this basically means

'For each Transmitter tx in transmitters...'

it iterates across every object in the collection, and runs them through the body of the loop.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to go through this for a better grip on the enhanced for loop syntax

http://java.sun.com/j2se/1.5.0/docs/guide/language/foreach.html
 
Ravaa Bal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both, that makes sense!
 
reply
    Bookmark Topic Watch Topic
  • New Topic