Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@OOPUniversity
Created November 9, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OOPUniversity/5eafc83df9d9ef93aebe to your computer and use it in GitHub Desktop.
Save OOPUniversity/5eafc83df9d9ef93aebe to your computer and use it in GitHub Desktop.
Demonstrates simple for loops, including a 'nested' loop which generates a multiplication table.
package main.java.com.oopuniversity.basics.loops;
/**
* Created by OOPUniversity on 11/15/2014.
*/
public class For {
public static void main(String [] args) {
for1();
for2();
for3();
}
public static void for1() {
System.out.println("for1");
for (int runCount = 0 ; runCount < 5 ; runCount ++ ) {
System.out.println("I am in a loop.");
}
}
public static void for2() {
System.out.println("for2");
for ( int i = 0 ; i < 10 ; i++ ) {
System.out.println("Loop iteration " + i );
}
}
/**
* Demonstrates 'nested' for loops
*/
public static void for3() {
System.out.println("for3");
for ( int i = 0 ; i < 5 ; i++ ) {
for ( int j = 0 ; j < 5 ; j++ ) {
int product = i * j ;
System.out.println (i + " X " + j + " = " + product );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment