Testing loop statements

A design question: which type of loop do you need? a definite loop ("for") or an indefinite loop ("while")

For any loop control structure, you need to consider 3 basic cases

None of these are necessarily error conditions, but you should make sure the code has been tested.

Can the first case happen with a "for" loop? Yes, it is possible.

     for i in range(num):
        #body
If num has the value 0, the body will never be executed.
     for line in infile:
       # body
If the file is empty, the body will never be executed.

Another thing to check on a loop is does it start and stop at the right time?

A question to check: are the correct statements inside the loop and are the correct statements outside the loop? In other words, are the statements being repeated the ones that should be?