Java Loop Control Statements

Java  Loop Control Statements are used when you need to execute a certain program code severally.The statements are executed sequentially one after the other.

Types of Java Loop Control Statements

1.Simple for loop

2.For each Loop

3.Labeled For Loop

1.Simple Java for loop

Just like in C++, simple java for loop is shown below.

First, an individual variable is initialized, then a certain condition is checked, javaincrement or decrement is done on the variable.

Simple Java for loop code Example:

 

Output:


2.For each loop

For each loop is used to transveJavacollections or arrays.This loop works on elements and not index.We don’t  need to increment  or decrement any value.

Syntax:

 

Example:

 

Output:

3.Labeled For Loop

Labeled for loop is used when there is a nested for loop.Its breaks and then continues.Break and continue keywords are used to perform these operations.

Syntax:

Example:

Output:

If the above code we used break cc,t the inner loop will be broken which has the default behavior of any loop.

Example:

Output:

4.Infinitive Loop in Java

Last and not least loop in java is infinitive.This loop means no end.This loop has two semicolons:

Syntax:

 

Output:

Next Topic: Java While Loop

previousnext

About the Author: Eric K

My name is Eric.Am a software developer with skills in Php,Mysql, Java , Android,Node.js Above all, I have certification in Cisco Networking Associate (CCNA) and holds degree in Information Technology. Hire me: Email : kawi3462@gmail.com