Results 1 to 2 of 2
  1. #1
    hungdukie is offline Member
    Join Date
    Nov 2008
    Posts
    32
    Rep Power
    0

    Question [SOLVED] Trouble understanding or expressions

    I am supposed to decide which of the following statements will not be evaluated in this expression:
    5 < 3 || 6 < 7 || 5 > 3
    I understand that in short-circuit evaluation, as soon as the value for the entire expression can be determined, the evaluation stops. So what I am guessing is that:
    5 < 3 is false so the evaluation continues
    6 < 7 is true so the value for the expression will be true and the evaluation stops due to short-circuit evaluation, therefore
    5 > 3 is not evaluated.
    Is this correct? I really am not sure if I have the concept right or not. I would appreciate any help with making sure I understand this.
    Last edited by hungdukie; 11-23-2008 at 12:15 AM. Reason: typo

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    That is a compiler issue, not a regular experssion issue. I would guess at it but it has been too long since I studied the matter.

    Canonical in my code is to do:
    Java Code:
    String aString = variable.getValue();
    if((aString != null) && (aString.length() > 0 ) && (aString.contains("a")) && (proceed == true)){....}else{}
    which saves face at product rollouts.

    Your sample uses OR operator so think of it like this: is it true that five is less than three? Well what happens if something is true here? if mail is here or Turkey is hot it cannot be Thanksgiving day and both be true so if you get up and check the mail and it is here, either it is the day before or you slept 24 hours.

    Under the reasonable person paradigm, we can just check the mail and if it is here, why bother to try to eat the turkey?

    It will be frozen and may be the day to set it in the lower refridg compartment but there is little utiltiy in biting it to see if it is done.
    Last edited by Nicholas Jordan; 11-23-2008 at 02:25 AM. Reason: bold tags and upper-case logical OR
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. [SOLVED] Understanding if else statements
    By hungdukie in forum New To Java
    Replies: 6
    Last Post: 11-18-2008, 08:56 AM
  2. [SOLVED] Help with understanding nullpointexcepion
    By soxfan714 in forum New To Java
    Replies: 4
    Last Post: 11-11-2008, 05:51 AM
  3. Replies: 3
    Last Post: 10-07-2008, 12:03 AM
  4. JSP Expressions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 11:13 AM
  5. Understanding Vectors
    By cbrown08 in forum New To Java
    Replies: 7
    Last Post: 11-05-2007, 07:56 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
  •