Using loops in Java

You can use loops to re-run a particular code segment until it satisfy a certain condition.

Basically there are 3 basic types of loops in Java.

  • While loop
  • For loop
  • Do-While loop

While Loop

Syntax :




For example :


x++ => increment the value of x by one

The printing statement will run 11 times until the condition becomes false.

For Loop

Syntax :





The code will execute until the condition becomes False.

Do-While Loop





This loop can be used to run a loop at least one times.


Likewise you can use the loops as you need to run over the same set of lines again and again.

Enhanced for loop will be discussed later.

Thank you.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s