Wednesday, 2 July 2014

Java for Loop

Here is a very basic example of a Java for loop:

andrew@UBUNTU:~/Java$ cat prog43.java
public class prog43
{
public static void main (String args[])
  {
  for(int x=3;x<=19;x=x+5)
    {
    System.out.println("x = "+x);
    }
  }
}
andrew@UBUNTU:~/Java$ javac prog43.java
andrew@UBUNTU:~/Java$ java prog43
x = 3
x = 8
x = 13
x = 18
andrew@UBUNTU:~/Java$