Consider the pseudo-procedure below:
--beg
if (condition_a)
condition_b = true;
while (condition_a and condition_b)
•••Do something that can mutate condition_a and/or condition_b•••
--end
condition_b
is an already existing condition that must be set to true
(if condition_a
is true
) before the loop will even start.
condition_a
is tested twice which is “unnecessary”. I want to remove the “unnecessary” test. [1][2]
I considered the following:
repeat-until
.- Set
condition_b
at the start of each loop iteration.
All will lead to multiple setting of condition_b
which is also an O(n) test of the condition (worse than my original intention).
What other approach will you suggest?
[1] The use of “unnecessary” is completely subjective and it is actually the premise of this question. I feel like the first test can be avoided and the second test, which is the most significant one, should suffice.
[2] If you disagree with it being unnecessary, please prove your claim of its necessity.