Wednesday, November 7, 2007

What choices did you face in developing your solution, and how did you choose among them?

When considering loops and iterations, one could use either the for loop, or the while loop, or the do-while loop. It is critical which one a programmer used in his / her program. A for loop would be used when the programmer wants to initialize a variable in the loop it self. A while loop is essentially similar to the for loop but, in a while loop, the initialization is done outside. The minimum number of times a while loop can run is 0 times. The do-while loop, however, runs at least once. The difference between a while loop and a do-while loop is when the condition expressions are considered. In a while loop, the conditions are tested before the statements are compiled, but in a do-while loop the statements are run once before the conditions are tested. Thus, a programmer should chose one of these three types of iterations wisely so that it would best fit his / her program.

No comments: