Wednesday, October 27, 2010

What is a loop?

Loops allows a programmer to repeat a block of code a number of times while some condition is true, or until some condition becomes true. For instance, a loop could be used to prompt a user for an answer until the correct input is entered.

A loop must contain a starting condition and an ending condition. It is very important that a loop is able to reach an ending condition or we end up with what what is called an ‘infinite loop’ – a loop that never ends. This can cause our programs to behave abnormally and may even cause a computer to ‘crash’.

No comments:

Post a Comment