Table of Contents
In this article, we will discuss the For loop in Java language with example
Java has three types of basic loops
The for loop used to evaluate and execute the set of Java statements repeatedly, until the test condition is false of the java program.
The for loop executes program when the Boolean expression evaluates and the condition is satisfied.
for loop Example
Example 1
this program display 1 to 10 natural number
class forloop{
public static void main(String args[]){
for(int x=0;x<=10; x++)
{
System.out.print(x); // print in same line because use print(x);
}
}
}
out put
Example 2
This program display first ten square number, using for loop
Output
If you use two semicolons (;;) in the for loop, it will be infinitive for loop
Output
This is infinite for loop
This is infinite for loop
This is infinite for loop
This is infinite for loop
This is infinite for loop
This is infinite for loop
This is infinite for loop
Ctr+c – control the flow
Output
1
2
3
4
5
6
7
8
9
10
…
…
…Ctr+c- to exit from the flow
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.