View Single Post
  #4   Report Post  
Posted to sci.electronics.design,alt.binaries.schematics.electronic,sci.electronics.cad,sci.electronics.basics
Tim Wescott[_5_] Tim Wescott[_5_] is offline
external usenet poster
 
Posts: 119
Default IF Statement Notation

On Thu, 20 Mar 2014 12:43:03 -0700, Jim Thompson wrote:

On Thu, 20 Mar 2014 14:14:23 -0500, Tim Wescott
wrote:

On Thu, 20 Mar 2014 11:51:34 -0700, Jim Thompson wrote:

Anyone know how to interpret this IF (I think) statement...

PMI=(PM=0)?((PM==0)?1000:PM):PMC

it's in a notation-style I don't understand.


It looks like C-style conditional operator (whose use is frowned upon,
particularly in cascade like that).

In C and C++,

ANSWER = THING ? THIS : THAT;

means that if THING is true, ANSWER = THIS. Of THING is false, ANSWER =
THAT.

In more traditional if-else notation, your statement expands to:

if (PM = 0)
{
if (PM == 0)
{
PMI = 1000;
}
else {
PMI = PM;
}
}
else {
PMI = PMC;


In English, does this mean:

If PM is exactly 0, PMI=1000
If PM is greater than 0,
PMI=PM Otherwise (negative PM?) PMI=PMC

I'm confused by the stacking :-(


Oh gosh, why should something so clear be confusing?

Yes, that's what it means (which is what JM said).

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com