Elseif Question

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
Guest

Elseif Question

Post by Guest »

This may be a dumb question, but is there a difference in using “else if” and using “elseif” in CSPro logic?

Can it be written as two words or is it always written as one word?

Thanks.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Elseif Question

Post by Gregory Martin »

There is a slight difference between the two formulations. The two following blocks of code do the same thing:
if A then
elseif B then
else
endif;

if A then
else if B then
else
endif;
endif;
Why is a second endif needed in the second block? It helps to indent the code to understand why:
if A then
else
    
if B then
    
else
    
endif;
endif;
Each else needs to be matched with an endif, whereas a grouping of if/elseif/else only must be matched with one endif. So effectively you can use "if" or "else if" to accomplish the same conditional checks, but with the latter syntax you will have many more endif statements, which might make your code look more awkward.


Last bumped by Anonymous on April 5th, 2012, 2:44 am.
Post Reply