Overcoming Common Pitfalls in Java Loops: Tips and Tricks

 

Overcoming Common Pitfalls in Java Loops: Tips and Tricks



Looping Statements are used to execute a statement several number of times based on the condition.In java language these are classified into following types.
1.For Loop
2.While Loop
3.Do While Loop

for:’for’ is a keyword in java language which is used to execute one block of statements several number of times based on the condition.
Syntax

for(initilization;condition;increment/decrement)
{


}

In the above syntax :
initilization is a starting value
condition is a ending value
increment/decrement is incrementation(++) or decrementation( — )

Display 1 to 10 Values Using For Loop

class Main
{
public static void main(String args[])
{
int x;
for(x=1; x<=10; x++)
{
System.out.println(x);
}
}
}

Comments