Results 1 to 5 of 5
  1. #1
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default simple loop syntax( ; ;), ( something : somthing)

    I'm curious as to all the different ways to write a for loop? I know how the standard
    Java Code:
    for(starting value; value to reach; increment value){
    }
    works. Could someone explain
    Java Code:
    for(something1 : something2){
    }
    I'm assuming it automatically starts at 0, something1 is the value to reach, and something2 is the increment value? Or maybe it increments++ start at something1 until it reaches something2?

    If there are any other styles of writing a for loop(also that :? thing in if statements is confusing) feel free to toss them in here with a little explanation also.

  2. #2
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default

    I'd also like to know...

  3. #3
    carderne is offline Senior Member
    Join Date
    Nov 2007
    Posts
    160
    Rep Power
    7

    Default

    Look here:
    The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

    That gives a basic rundown of the two types.

    for(item : array) is used to iterate through an array or collection.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by carderne View Post
    Look here:
    The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

    That gives a basic rundown of the two types.

    for(item : array) is used to iterate through an array or collection.
    In most of the time I found that lots of well experienced Java programmers use this way. They say that, iteration on an array gives more performance in execution within short period of time in VM.

    But the case is, use default iteration increment all the time, 1

Similar Threads

  1. [SOLVED] Looking for web.xml syntax doc
    By Norm in forum Java Servlet
    Replies: 2
    Last Post: 08-21-2008, 07:59 PM
  2. Replies: 13
    Last Post: 07-06-2008, 09:11 AM
  3. Cannot get passed these syntax errors
    By MrKP in forum New To Java
    Replies: 1
    Last Post: 05-12-2008, 07:05 AM
  4. syntax error
    By gabriel in forum New To Java
    Replies: 3
    Last Post: 08-03-2007, 03:26 PM
  5. Help with removing somthing once inputed.
    By fegiflu in forum New To Java
    Replies: 8
    Last Post: 07-26-2007, 10:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •