Thursday, July 7, 2011

Learning Java 10 - Loop_for

Another types of loop is the "for loop". This "for loop" and "loop while" has the same function but they have different source code. Here are some simple example of this type of loop.

import java.util.*;
public class for1{
    public static void main(String[]args){
    for(int x=0;x<=5;x++)
    {
    System.out.println(x);
    }
}}
output:
0
1
2
3
4
5


import java.util.*;
public class for1{
    public static void main(String[]args){
    for(int x=5;x>=0;x--)
    {
    System.out.println(x);
    }
}}
output:
5
4
3
2
1
0



import java.util.*;
public class for1{
    public static void main(String[]args){
    for(int x=5;x>=0;x--)
    {
    System.out.print(x);
    }
}}
output:
543210


These three example of java program are "for looping".