ADICON Support Forum Applied Digital, Inc.
Page 1 of 1 1
Topic Options
#21137 - 06/04/09 01:37 AM Use of Skip for performance
chewbarker Offline
newbie


Registered: 01/01/07
Posts: 23
I think I know the answer for this, but I was wondering if there is any benefit of having skips to avoid a small number of if statements (Big blocks I know skip is an advantage).

For example:

IF condition true
Then ...
Then Skip X
If condition false
Then ...
X

I am expecting that it maybe not necessary for performance as just having:

IF condition true
Then ...
Then ...
Then ...
If condition false
Then ...
Then ...
Then ...
X

Is it true that if the IF condition is not true then the "Then" statements are skipped automatically, in the example above moving to X.

Thanks in advance

Matt

Top
#21142 - 06/04/09 05:33 AM Re: Use of Skip for performance [Re: chewbarker]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
As you said, for just a few lines there is little advantage in skipping them, but for large groups of similar commands such as routines only executed when you're away from home, night routines, macros triggered only when IR is received, etc then you can improve not only performance but also make your code a lot cleaner (by using nested logic).

Yes, if the condition(s) test false as a complete logic test, then the THEN statements will not be executed (but they are not "skipped" as such, the program still needs to read it and see that it is a THEN statement).

I like using the SKIP TO statement to create C language-like code, just because of the familiarity with C logic flow. In the C language, the equivalent to the Skip To statement is (most often) the open brace "{". So if I wanted to do something like this in C:

if (away_mode == TRUE)
{
then do this
then do that
}

I will do this in C-Max:

IF V1-AwayMode = 1
ELSE Skip to line X
THEN do this
THEN do that
(line x)
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#21146 - 06/06/09 01:59 AM Re: Use of Skip for performance [Re: Guy Lavoie]
chewbarker Offline
newbie


Registered: 01/01/07
Posts: 23
Hello Guy,

Thanks for the tips. I didnt think of presented it exactly that way, I like your style.

Makes good sense.

Matt

Top
#21153 - 06/15/09 10:08 AM Re: Use of Skip for performance [Re: chewbarker]
Mike Chwojdak Offline
journeyman


Registered: 01/15/03
Posts: 81
Loc: Rochester, NY
Guy,
I didn't know you could put the ELSE before the THEN.

Top
#21155 - 06/15/09 05:11 PM Re: Use of Skip for performance [Re: Mike Chwojdak]
dahlheim Offline
junior


Registered: 12/31/08
Posts: 41
me neither...
Top
#21156 - 06/15/09 06:23 PM Re: Use of Skip for performance [Re: dahlheim]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6401
Loc: Montreal, QC, Canada
It doesn't matter what order you put THENs and ELSEs. They are simply evaluated on a line by line basis, based on the last logic test. If the last logic test was true, any THENs will be executed, otherwise the ELSEs will be the ones executed.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#21867 - 06/05/10 12:43 PM Re: Use of Skip for performance [Re: Guy Lavoie]
Marty Offline
newbie


Registered: 01/24/04
Posts: 23
Loc: Massachusetts, U.S.
Well that's easy to remember. I haven't modified my code in years, and I was poking around looking for a couple of coding nuggets. That info is just what the doctor ordered!
Top
Page 1 of 1 1


Moderator:  Dan Smith, Monte G, ADI Tech Support, Guy Lavoie 
Hop to:
Who's Online
1 registered (kuro) and 21 anonymous users online.
Recent Posts
Basic Ocelot/IR-100 Question
by kuro
02/09/12 04:16 PM
SECU16IR Output Connecting To A Xantech Connecting Block
by Jean-Marie
02/09/12 08:36 AM
SECU16IR Output Connecting To A Xantech Connecting Block
by Jean-Marie
02/09/12 08:34 AM
how to post an icon
by manu
02/03/12 03:40 AM
Command Pair
by kuro
02/01/12 12:49 AM
Shout Box

Newest Members
feshh, manu, kuro, chuck214, Funkhauser
2747 Registered Users
Forum Stats
2747 Members
19 Forums
3837 Topics
22714 Posts

Max Online: 67 @ 08/16/11 03:08 PM
February
Su M Tu W Th F Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29