Boolean Expression

P

Paul Wagener

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!
 
J

Joona I Palaste

Paul Wagener said:
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
*/

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?
 
A

adam

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top