0
$\begingroup$

Simple question from an algorithm noob...

If $i=1$ then the inner loop will include what I believe to be an invalid range. Is this acceptable pseudocode?

For i=1 to n
  For k=1 to i-1
    ...
$\endgroup$
  • 1
    $\begingroup$ "If i=1 then the highlighted text will include what I believe to be an invalid range". Why is it an invalid range? Is empty set a valid set? Is empty range a valid range? $\endgroup$ – Apass.Jack Dec 23 '18 at 2:51
1
$\begingroup$

It is acceptable.

The loop says “do something for each integer $k$ in some range”. If there is no integer in that range, the loop just won’t do anything.

$\endgroup$
  • $\begingroup$ Thank you for clearing that up for me. $\endgroup$ – Chrismo16 Dec 23 '18 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.