Once again, I’m writing a blog inspired by a search phrase that brought someone to my blog. Today’s phrase is: “in if statement, can we calculate”.

First of all, it depends on the programming language you’re using. Some programming languages allow this, others don’t. Here is how you might do a calculation in an IF statement:

IF ( (  a+b ) = c ) THEN
…do some stuff
ENDIF

However, many of the proprietary languages we use don’t support this. I would avoid using them. Even if they work, today, in a future version, they might not work. This is one of those things that seems cool and efficient to do but which doesn’t save you enough time, today, to gamble on a possible non-working future.

Thus, for all proprietary languages, or if in any doubt, at all, do it this way, instead:

d = a + b
IF ( d = c ) THEN
…do some stuff
ENDIF

Of course, everyone expects you to use better variable names than this, just to mention it. Also, the periods represent and indentation, which I can’t quite get to work here in my WordPress postings.

Gloria Metrick
GeoMetrick Enterprises
http://www.GeoMetrick.com/

Do you agree? Disagree? Have something to Add? Here's your chance - make a comment!