Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: The meaning of the characters "?" & ":" in for loops

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    My Mood
    Fine
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default The meaning of the characters "?" & ":" in for loops

    May someone please advs the meaning of these characters when used in for loop(are these operators)?
    Also, Pls advs what is the name of the api which explaines them? i treid looking for them in the java.lang package api, no luck.

    Thank you in advance for the help.


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: The meaning of the characters "?" & ":" in for loops

    Can you post an example? This looks like the ternary operator to me, not like a for loop.

  3. The Following User Says Thank You to PhHein For This Useful Post:

    AlonOfir (December 11th, 2013)

  4. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: The meaning of the characters "?" & ":" in for loops

    Yes, those are operators. They are not specific to for loops (as PhHein said).

    The two combined form a ternary operator (i.e. 3 parameters).

    a ? b : c

    How to read this:

    If a is true, then evaluate b. Else, evaluate c.

    Basically it condenses an if/else statement into an expression fragment.

  5. The Following User Says Thank You to helloworld922 For This Useful Post:

    AlonOfir (December 11th, 2013)

Similar Threads

  1. Understanding layers of system logic. Clarity for what "SDK" & "JDK" mean
    By MilkWetGhost in forum Java Theory & Questions
    Replies: 1
    Last Post: October 3rd, 2013, 12:25 PM
  2. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  3. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  4. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM