By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,348 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,348 IT Pros & Developers. It's quick & easy.

simple test

P: n/a
Why does this test as not true.

if (!1==2) echo 'true'; else echo 'nottrue';

It seems like it should be true.

May 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
gr*****@reenie.org wrote:
Why does this test as not true.

if (!1==2) echo 'true'; else echo 'nottrue';

It seems like it should be true.
IMHO Operator precedence.
you are negating 1 instead the whole expression.

How to negate whole expression:
if (!(1==2)) echo 'true'; else echo 'nottrue';

Hendri Kurniawan
May 2 '07 #2

P: n/a
On May 2, 12:43 am, Hendri Kurniawan <ask...@email.comwrote:
grou...@reenie.org wrote:
Why does this test as not true.
if (!1==2) echo 'true'; else echo 'nottrue';
It seems like it should be true.

IMHO Operator precedence.
you are negating 1 instead the whole expression.

How to negate whole expression:
if (!(1==2)) echo 'true'; else echo 'nottrue';

Hendri Kurniawan
Ok thanks. That makes sense. Or, of course,
if (1!=2)) echo 'true'; else echo 'nottrue';

May 2 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.