Related post

Java For loop | Zhullyblog

 


FOR LOOP IN JAVA

A loop is used to execute or iterate a statement repeatedly until a certain condition is met. In this tutorial, we would be talking basically about for loop but in context, there are 3 different types of loop which are for loop, while loop and do..while loop.

So let's dive into for loop people.


SYNTAX



for ( initialization ; condition; increment/decrement) {

  //Statement;

}




From the syntax, there are 4 key terms that you need to understand. They are:


 • Intialization : The first thing that need to be done when you wanna use a for loop is initialization. You need to declare a variable and assign a value to the variable. 


 • Condition : The next is to state the condition the statement must satisfy before execution starts.


 • Increment / decrement : The next is to either increase the variable or decrease.


Statement : The statement is the last thing that needs to be written. 




Here is an example.

For loop in javs



//by Zhullyblog

public class sample{

 public static void main(String[] args) {

  for( int i = 1; i<10; i++){

   System.out.println("The value of i is :" + i); 

   }

  }

}



Result

For loop example

Let's move


Break statement in Java


Continue statement in Java


Inheritance in Java


Please share 







Follow us on



Comments