Java Program using For Loop…

For Loop:

Syntax:
for(expression1;expression2;expression3)
{
Statements;
}
      Expression1 – Initialization
      Expression2 – Condition
      Expression3 – Increment / Decrement
Example:

class ForTick
{
  public static void main(String args [])
  {
    int n;
    for(n=10;n>0;n–)
    System.out.println(“Tick ” + n);
  }
}
Output:

D:java>java ForTick
Tick 10
Tick 9
Tick 8
Tick 7
Tick 6
Tick 5
Tick 4
Tick 3
Tick 2
Tick 1

Add Comment