logic comparator Question

M

Mike Langworthy

Hello all.

I am a total newb and am wondering how you test multiple questions in one if
statement without nesting them

for example, how do i test the following

is Variable greater than ten and not less than 5
 
M

Marc Gravell

As posed, it is a little odd (read the tests carefully and you'll
see); however, to test if something is greater than 5 and not more
than 10:

if (value > 5 && value <= 10) {

}

&& is "and"; || is "or"; both short-circuit, meaning that if the
left-hand-side of && returns false, the right hand side never
evaluates; ditto if the left-hand-side of || returns true

Marc
 
J

James Swindell

Mike,

If the variable is greater than 10, isn't it already not less than 5? What
are you looking to do?

James
 
J

James Swindell

Mike,

Sorry, what I neglected to include was your answer for syntax. I would
appear like this:

if (variable > 10 && variable >= 5)
{
}

James
 
M

Mike Langworthy

sorry poor wording

i meant less than 10 more than 5

i was trying to verify multiple conditions within an if loop.
 
M

Michael Weber

Mike Langworthy said:
sorry poor wording

i meant less than 10 more than 5

i was trying to verify multiple conditions within an if loop.

You could try something like this :

// if ( not not not not not not ( not not ( less than 10) and not
not ( more than 5) ) )
if ( !!!!!! ( !! ( var < 10 ) &&
!! ( var > 5 ) ) ){

}

! is equivalent to ¬

;)

Best Regards,
Michael Weber
 

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

Top