Boolean Expression

Discussion in 'Java' started by Paul Wagener, Nov 4, 2004.

  1. Paul Wagener

    Paul Wagener Guest

    Hi folks,
    Anyone having an idea of how testing for the following
    condition in a loop:

    if (x/5 == true)break; // this doesn't compute of course


    /*
    * x being a double number
    */

    Thanks!
    Paul Wagener, Nov 4, 2004
    #1
    1. Advertising

  2. Paul Wagener <> scribbled the following:
    > Hi folks,
    > Anyone having an idea of how testing for the following
    > condition in a loop:


    > if (x/5 == true)break; // this doesn't compute of course



    > /*
    > * x being a double number
    > */


    > Thanks!


    Doubles can't be compared to booleans. What do you expect?
    Or to put it another way:
    What do you want to do? Exactly *WHEN* do you want the loop to break?
    What condition must x be in for the loop to break? What numbers should
    work and what shouldn't?

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-------------------------------------------------------- rules! --------/
    "It was, er, quite bookish."
    - Horace Boothroyd
    Joona I Palaste, Nov 4, 2004
    #2
    1. Advertising

  3. Paul Wagener

    adam Guest

    > Hi folks,
    > Anyone having an idea of how testing for the following
    > condition in a loop:
    >
    > if (x/5 == true)break; // this doesn't compute of course
    >
    >
    > /*
    > * x being a double number
    > */
    >
    > Thanks!
    >


    If you want to test whether x is divisble by 5, you could use the modulus
    operator (calculates the remainer of x/5, which'll be 0 if x is divisible by
    5):

    if (x%5 == 0) break;

    adam
    adam, Nov 4, 2004
    #3
  4. Paul Wagener

    Paul Wagener Guest

    Thanks a lot!

    The mod does the job quite fine.

    Paul

    "adam" <> schrieb im Newsbeitrag
    news:cmdt2u$m17$...
    >> Hi folks,
    >> Anyone having an idea of how testing for the following
    >> condition in a loop:
    >>
    >> if (x/5 == true)break; // this doesn't compute of course
    >>
    >>
    >> /*
    >> * x being a double number
    >> */
    >>
    >> Thanks!
    >>

    >
    > If you want to test whether x is divisble by 5, you could use the modulus
    > operator (calculates the remainer of x/5, which'll be 0 if x is divisible
    > by 5):
    >
    > if (x%5 == 0) break;
    >
    > adam
    >
    Paul Wagener, Nov 4, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anonymous
    Replies:
    1
    Views:
    969
    Roedy Green
    Nov 24, 2003
  2. Replies:
    7
    Views:
    1,570
  3. Replies:
    0
    Views:
    652
  4. J Leonard
    Replies:
    4
    Views:
    12,628
    Mark Space
    Jan 19, 2008
  5. Metre Meter
    Replies:
    7
    Views:
    357
    Metre Meter
    Aug 6, 2010
Loading...

Share This Page