• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difficulty understanding this for loop...  RSS feed

 
Ravaa Bal
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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.
 
ani pillai
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you both, that makes sense!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!