MAMEWorld >> The Loony Bin
View all threads Index   Flat Mode Flat  

Pi
Allergic to life
Reged: 09/20/03
Posts: 6449
Loc: Room 101
Send PM
Re: quick programming question
11/12/15 05:36 PM


> In my current class, we are required to assess our own code, as well as 2 random
> other students' code. It is pseudo code, so it doesn't really conform to a specific
> language, so I must ask: Will the following work in ANY language?
>
> If Variable NOT == 0

NOT is an unary operator. == (equal to) is a binary operator. Placing the NOT there will make it negate the equal to operator. So that specific syntax has to fail in every language I know of. Only these constructs would work, be it pseudocode or real code in a specific language:
if variable == not(0)
if not(variable == 0)

One could argue that in certain situations, a minus sign (-) is also an unary operator but it wouldn't matter in this example since the operator precedence would unambiguously interpret the following in the same way:
if variable == not -1
if variable == not(-1)

However even if you forget about operator precedence and specify parentheses all around everything, it's clear that the construct you ask about doesn't make sense:
if variable not(== 0)

Operator precedence has always been one of my weak spots in writing code so I tend to overuse parentheses to ensure that things are interpreted in the way I need.


Wound up, can't sleep, can't do anything right, little honey / Oh, since I set my eyes on you. / I tell you the truth.
I can't get it right / Get it right / Since I met you...







Entire thread
Subject Posted by Posted on
* quick programming question URherenow 11/12/15 03:29 PM
. * Re: quick programming question Robbbert  11/13/15 02:56 AM
. * Re: quick programming question TriggerFin  11/13/15 08:04 AM
. * Re: quick programming question URherenow  11/13/15 11:22 AM
. * Re: quick programming question Pi  11/12/15 05:36 PM
. * Re: quick programming question krick  11/13/15 05:29 AM
. * Re: quick programming question RATMNL  11/12/15 03:57 PM
. * Re: quick programming question URherenow  11/13/15 01:56 AM

Extra information Permissions
Moderator:  GatKong 
0 registered and 17 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 1550