Java for
What is Java for Loops?
When we want to execute a block execute multiple time then we use loop.It executes until condition is true.
The for
executes a block of code as long as a given condition is true. It has multiple statements. This is very popular in all loops.
for (initialization; condition;increment/decrement) {
// code block to be executed
}
Initialization: It executes at once.
Condition: This check until get true.
Increment/Decrement: this is for increment or decrement.
Sample program with if
Write a program or WAP to print 1 to 10 using for loop.
class SampleFor
{
public static void main(String args[])
{
for(int num= 1;num <= 10;num++)
{
System.out.println(num);
}
}
}
Output:
1 2 3 4 5 6 7 8 9 10java java tutorials learn java study java