Using THEN to improve IF clarity

Posted on Sunday, February 8th, 2009

Something that came up recently on CW-Talk2 which I found to be a very interesting insight.

In Clarion the help has this description for “IF”:

1
2
3
4
5
6
7
IF logical expression [ THEN ]
  statements
[ ELSIF logical expression  [ THEN ]
  statements ]
[ ELSE
  statements ]
END

Quite often in production code I have seen examples of many, many lines of expressions after the IF, the developer using the “|” line continuator to span multiple lines.

The comment, I think it was Marg G, was to use THEN to make it clear where the <expressions> have finished and the <statements> have begun:

1
2
3
4
5
6
IF <some condition> OR |
   <some other condition> OR |
   <even more conditions> |
THEN
  ! Do something
END

Pretty simple and very neat!

It will be nice to see if C7 supports code folding for this kind of structure as well…

Categorized as Clarion, Clarion, General

Leave a Reply