Results 1 to 5 of 5
  1. #1
    peterhabe is offline Member
    Join Date
    Jul 2010
    Posts
    43
    Rep Power
    0

    Default Comparisions for while loop

    How would i write the following as a comparison for a while loop or if statement:
    verticalVelocity equals 0 and angle.getValue() does not equil 0 or 90

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Try replacing each of those comparison "phrases" with the corresponding symbols and see what you come up with.

  3. #3
    peterhabe is offline Member
    Join Date
    Jul 2010
    Posts
    43
    Rep Power
    0

    Default

    I've tried but if you do a direct "translation" into java language you get:
    Java Code:
    verticalVelocity == 0 && angle.getValue() != 0 || 90
    which donen't work. The best I can come up with is:
    Java Code:
    verticalVelocity == 0 && angle.getValue() != 0 || verticalVelocity == 0 && angle.getValue() != 90
    but this isn't the same as my origonal statement in the my first post.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Starting point is your first attempt. Put parens around the rest of the statement after the && and add make the part after the || "complete" (i.e. add the condition you are comparing "90" to).

    The second example would also work (but is "wordy") if you put parens around the two "halfs" of the statements (i.e. on each side of the ||).

    The thing you are not thinking of is the "grouping". You acheive that through selective use of parens.
    Last edited by masijade; 08-31-2010 at 11:54 AM.

  5. #5
    peterhabe is offline Member
    Join Date
    Jul 2010
    Posts
    43
    Rep Power
    0

Similar Threads

  1. Replies: 5
    Last Post: 04-30-2010, 05:05 PM
  2. Do While Loop
    By s4rd59 in forum New To Java
    Replies: 2
    Last Post: 02-14-2010, 03:29 PM
  3. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 08:46 PM
  4. While loop
    By verbazon in forum New To Java
    Replies: 5
    Last Post: 02-25-2009, 01:29 AM
  5. while loop
    By michcio in forum New To Java
    Replies: 5
    Last Post: 01-27-2008, 12:56 AM

Posting Permissions

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