12:27 am - Tuesday March 19, 2019

The Looping Statement in java with Example Program

Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

The Looping Statement

Looping Statements:

  • for loop
  • while
  • do-while

for loop statement:

The for loop is an entry-controlled loop.  for loop is a repetition control structure that executes a number of times. For loop in java includes a intializer, a condition and a counter expression. It is possible to include several expressions using comma delimiter. The syntax of for loop is

for (initialization; test-condition; increment)


Block of statements;


while statement:

while statement is used to test the condition. It is an entry-controlled loop. If the condition is true the loop executes otherwise it exit from the loop. The syntax of while loop is,

while (test condition)


Block of statements;


do-while statement:

The do-while is an exit-controlled loop. It enters into the loop before testing the condition. If the condition is true it enters into the looping statements otherwise it terminates from the loop.

The difference between the while and do-while statement is condition testing. In while loop, it initially checks the condition before entering into the loop. Based on the condition looping statement occurs. In do-while statement, first it enters into the looping statements and finally it checks the condition. If the condition is true, looping statements begin or else it exits from the loop. The syntax for do-while loop is,



Block of statements;



while ( test condition);


Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply