Results 1 to 6 of 6

Thread: Shorthand ?

  1. #1
    gatzke is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default Shorthand ?

    I'm wondering what this style of coding is called:

    Instead of this:

    if(a == b)
    {
    do stuff;
    }

    I saw this:

    a==b & do stuff;

    The "if" and braces were left out. What's this called and can it be done in Java?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Neither of the code snippets you posted are valid java syntax, so it's anybody's guess what the real question is here.

    db

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Perhaps you're talking about the ternary operator which goes something like this:

    Java Code:
    (a == b) ? /* do if true */ : /* do if false*/;
    A link regarding this is here: Java Lesson - Lesson 07: Conditional Statements

    then again, I could be guessing at your question wrong,... who knows? I have to second Darryl's recommendation on your giving us more information with your question(s).

    A great resource that has helped me and will probably help you is an article entitled How To Ask Questions The Smart Way. It will tell you how to formulate your questions so that the folks here will be better able to answer them. Good luck.
    Last edited by Fubarable; 01-24-2009 at 02:21 PM.

  4. #4
    gatzke is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default

    Thank you Fubarable - just what I was looking for.

    And Darryl - how is the "if" statement invalid?

  5. #5
    Jus
    Jus is offline Member
    Join Date
    Jul 2009
    Posts
    1
    Rep Power
    0

    Default Sad

    gatzke, ignore both Darryl.Burke and Fubarable. They seem to be high on their horses about dishing out help. If Darryl couldn't understand your question, he shouldn't have responded. At least Fubarable (and any other kid that knows basic java) could have figured out what you were trying to ask. But then he shoots himself in the foot by saying he agrees with Darryl. And he is the moderator? Jeez.

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default A couple of comments...

    @gatzke: Just a reminder ... the == operator shouldn't be used for comparing strings. To compare strings use the equals() method.

    @Jus: I agree that Daryl's comment could have been better, but the OP seems top have gotten the answer he was looking for from Fubarable. You are welcome to share your knowledge with the rest of the forum, just remember to keep your posts polite.

    Thanks,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Posting Permissions

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