Why Do We Need FOR Loop – Essay Example

The paper "Why Do We Need FOR Loop" is a wonderful example of an essay on logic and programming.
Recursion to check for a certain condition(s) forms an important part of programming and coding. The evolution of programming languages has meant that recursion can be performed using many different tools including the WHILE and the FOR loop. Each tool provides its own set of advantages and disadvantages for implementation. As a rule of the thumb, the WHILE loop is more flexible and versatile than the FOR loop, especially for larger iteration blocks.
Primarily, the WHILE loop performs recursion while a certain condition is not met, whereas a FOR loop performs recursion for a fixed number of known condition(s) (Stack Exchange, 2011). The WHILE loop provides the inherent flexibility of testing for continuation at the top or at the bottom of the loop using the WHILE DO and the DO WHILE methods respectively. It must be recognized that the WHILE loop provides greater flexibility for execution when multiple unknown possibilities are possible, compared to using a FOR loop for finite known possibilities (Math Bits, 2014).
In terms of differences between the WHILE and FOR loops for memory usage and execution speed, there are only minuscule differences that only present themselves for situations with myriad recursion possibilities (Bytes, 2010). Testing for execution speed reveals that the WHILE loop is slightly faster than the FOR loop, but it must be kept in mind that a very large number of iterations must be performed for such differences to fully emerge (Stoimen, 2012).