The infinite or endless loop is a sequence of
instructions in computer program which loops endlessly due to:
·
the loop having no
terminating condition
·
having one terminating condition that can never be
met, or
·
one that causes the loop to start over.
In
older operating systems with cooperative multitasking, infinite loops normally
caused the entire system to become unresponsive. Today computers with
now-prevalent preemptive multitasking model, infinite loops usually cause the
program to consume all available processor time, but can usually be terminated
by the user.
In
case of countdown, we can prove that the loop terminates because we know that
the value of n is fine (in previous example it was 10), and we can see that the
value of n gets smaller each time through the loop, so eventually we have to
get to 0. Other times a loop is obviously infinite because it has no iteration
variable at all.
Nema komentara:
Objavi komentar