Velocity Reviews > Java > Boolean Expression

# Boolean Expression

Paul Wagener
Guest
Posts: n/a

 11-04-2004
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!

Joona I Palaste
Guest
Posts: n/a

 11-04-2004
Paul Wagener <(E-Mail Removed)> 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 ((E-Mail Removed)) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"It was, er, quite bookish."
- Horace Boothroyd

Guest
Posts: n/a

 11-04-2004
> 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;

Paul Wagener
Guest
Posts: n/a

 11-04-2004
Thanks a lot!

The mod does the job quite fine.

Paul

"adam" <(E-Mail Removed)> schrieb im Newsbeitrag
news:cmdt2u\$m17\$(E-Mail Removed)...
>> 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;
>
>