Blog Introductions
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services. Java Loops for loop while loop do while loop | Java tutorials Bestitworriors
In this blog contains tutorials about HTML Tutorials, Python Tutorials, CSS Tutorials, How to, PHP Tutorials, Java Tutorials, C++ Tutorials, Tutorials, Examples, Source code,Learning,
Tips and Software development services. Java Loops for loop while loop do while loop | Java tutorials Bestitworriors
Java Loops for loop while loop do while loop
Java Loops for loop while loop do while loop | Java tutorials Bestitworriors - Java loops are use to execute a block of code for many times untill specific condation match . Java support for,while , do while loops.The purpose is same for all loop but use according to given condation.Java loops are very usefull for iterate the block of code multipull time.
Some Key Points of Java Loops
- Java loops iterate multipull time untill given condation occure
- If you know the iteration time you can use for loop instead of while loop
- Do while loop execute block of code first and then check the condation
- We can use continue and break statements in the loops
- Continue statement use skip the current iteration
- Break statement use to jump out of loop when condation match
- Loop are best practice for iterate the block of code
Code
public
class loopss {
public static void main(String[] args) {
int var1 = 0;
while (var1 < 5) {
System.out.println(var1);
if (var1 == 3) {
break;
}
if (var1 == 2) {
var1 + +;
continue;
}
var1 + +;
}
int
var2 = 0;
do
{
System.out.println(var2);
var2 + +;
}
while (var2 < 5);
for (int var3 = 0; var3 < 5; var3++) {
System.out.println(var3);
}
String[]
Months = {"January", "Feburary", "March", "April"};
for (String i: Months) {
System.out.println(i);
}
}
}
Out Put
0
1
2
3
0
1
2
3
4
0
1
2
3
4
January
Feburary
March
April
0 Comments