I know you might have confused with While Loop & Do-While Loop. Yeah, yeah For Loop... but trust me this is gonna be easy lot more than While Loop & Do-While Loop.
A For loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
Let's go for coding...
public class main {
public static void main(String []args){
for (int counter = 1; counter < 10 ; counter= counter + 1){
System.out.println(counter);
}
}
}
The advantage of the "For loop" is you can declare a variable inside
the loop.
Next big thing is you also can write the condition in the same line.
Let's for another similar one...
public class main {
public static void main(String []args){
for (int counter = 2; counter < 15 ; counter= counter +2){
System.out.println(counter);
}
}
}

Ugh if you have any problems with these loops just visit this link & get cleared.


- Yeah, the results will be even numbers up-to 14..
C'mon guys now you should be able to mind map the results.
No comments:
Post a Comment