Loops are a common occurrence in any programming language. They are used to perform repetitive tasks to achieve an objective. Usually there are three types of loops to be found in programming languages.
Condition tested – Loops of this type repeat their task until a specified condition returns the desired result. The condition can be specified at the beginning, middle or at the end of the loop. This is because the condition will be testing a result returned by the loop. Therefore, the placement of the condition really depends on what type of operation the loop is performing.
Counted – These loops are performed for a specified number of times. A loop can be used, for example to get 100 names entered. So the code would ask “Enter Name 1″, “Enter Name 2″ and so on until the number 100 was encountered. Once it hits this number, this loop stops. Some of the lesser programming numbers do not feature this type of looping as they consider it to be part of Condition Tested Looping.
Endless – This type of loop is used for special purposes. They are designed to continue looping forever until the program crashes, the computer is physically turned off / rebooted or it receives data that satisfies its only EXIT condition. A somewhat common use for this type of looping is for monitoring messages from the OS. Using this type of loop for any purpose requires more in-depth knowledge of how looping affects processing and memory requirements.
Loops are used by programmers to replace a piece of code which has to be repeated X number of times, where X is either known or unknown. Thorough knowledge of this aspect of programming is a must for any programmer.
