Posted by
Zhullyblog
on
- Get link
- X
- Other Apps
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.
//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
Let's move
Introduction to Java programming
How to declare a variable in Java
If, if..else statement in Java
Please share
Comments
Post a Comment