×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
On 04 Oct 2013 14:25, Glenn Gundermann wrote:
Forgive the trivialness of this question but I am wondering if you
smart folks can answer this.
Compare these two statements:
If booleanVar;
If not booleanVar;
Do both of these take the exact same number of internal instructions
for the test or does the second statement take an extra step?
It depends... On the definition of "internal instructions", among
other things.
For a non-boolean variable... Typically one MI instruction effects
the type-specific data comparison, and that instruction is coded with
either the extension <branch-on-equal> or the extension <branch-on-unequal>.
For a boolean variable, the effect should be the same, because the
RPG boolean variable is effectively just another scalar data type. The
obvious benefit however [over other data types with more than a binary
yes|no type of comparison\answer], is that the generated code can be a
comparison against an effective *true or *false, irrespective of the
"NOT" in the predicate; i.e. in the following two sets of predicates,
the three predicates in each set are identical:
If BooleanVar then...
If BooleanVar='1' then...
If Not BooleanVar='0' then...
If Not BooleanVar then...
If Not BooleanVar='1' then...
If BooleanVar='0' then...
The RPG likely generates code that consistently executes the next
instruction on true [or false] and then executes the branch\GOTO on
false [or true]. Thus the impact is less about either what or how many
instructions are generated, but about the overall percentage of actual
evaluations will be to true vs to false on either form of the predicate.
Even so, the evaluation which follows the non-branched path might just
encounter a branch-unconditional somewhere later, to avoid whatever code
exists for an else-path.
As an Amazon Associate we earn from qualifying purchases.