# Boolean Expression

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

1. ### Paul WagenerGuest

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

2. ### Joona I PalasteGuest

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

3. ### adamGuest

> 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
4. ### Paul WagenerGuest

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

### 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.