Loops In Java

Loops in Java

Java as a vast language has many topics to focus on. One of them is loops. Loops are used to provide continuity to a program where a statement is implemented
until the condition is true or in simple language for running the provided statements until the provided condition is true .There are three types of loops:-

  1. While
  2. Do While
  3. For

While Loop :-

While loop is used for implementing a statement where initialization of the used variable is done before the condition given. In simple language we can say that
first the compiler will check the condition if it is true only then the statements will be implemented.For example:-
while(i <= 10){ “The statement which has to be implemented” }etc.

Do While :-

Do while loop is the same as while loop but there is only one specific difference i.e. do while loop implements the statement at least once before
checking the condition.
For example :- do{
“The statement which has to be implemented”
}while( i <= 10)

For :-

For loop is a loop in which the initialization of the variable, the condition as well as the rate of increment or decrement provided in the same statement i.e.
first a value will be assigned to a variable then the condition will be checked whether it is true or false and then the value of the variable will be incremented
or decremented as per the user’s requirement.
For example:-
for(int i = 0, i <= 10 , i++) { “The statement which has to be implemented” }

Share with your friends:

Leave a comment

Your email address will not be published. Required fields are marked. *