Monday, August 30, 2010

Java Loop

Loops provide efficient way for repeating a piece of code as many times as required. Java has three ways to use the loop control structures and these are:

For Loop: The ‘For-Loop’ is used when we know in advance how many iteration is required
While Loop: The while loop is used when we do not know in advance the number of iterations required so each time before entering the loop the condition is checked and if it is true then the loop get executed
Do-While Loop: The do-while loop is always executed at least once and then the condition is checked at the end of the loop. Developer has to avoid using the do-while loop since it marks major bottleneck in the code.

Since loop repeats the piece of code therefore it gives more cause for performance and need to be very careful during the implementation

No comments:

Post a Comment