Now a variable can be off, on, or neither off nor on. A three-valued indicator? Here's how it's done.
Declare a two-byte character variable.
D SomeVar s 2a inz(*off)
SomeVar is *ON if it holds two ones, *OFF if it contains two zeros, and is neither *ON nor *OFF if it has one one and one zero.
Now you can code expressions like these:
if SomeVar = *on;
DoWhatever();
endif;
if SomeVar = *off;
DoThis();
endif;
if SomeVar <> *on and SomeVar <> *off;
DoSomething();
else;
DoSomethingElse();
endif;
if SomeVar = *on or SomeVar = *off;
DoSomething();
else;
DoSomethingElse();
endif;
Don't those last two ifs look weird? Believe it or not, it's possible for the else branches to execute.
Tuesday, December 18, 2007
Subscribe to:
Post Comments (Atom)
2 comments:
Hi Tamilmalar,
I'm glad you found the three-valued indicator tip of interest, but you would better serve your readers if you would credit the original author and perhaps link to the original post.
Ted Holt
I really question the three valued indicator. The purpose of writing code is to establish clarity of thought, not tricky code.
I enjoyed most of your other postings, and like yourself, am going down the Agile path of SW design. But this kind of code, although practical in rare cases, is not soemthing to let juniors think is good.
Post a Comment