Created
November 9, 2015 13:59
-
-
Save OOPUniversity/434a714a9d05ac642635 to your computer and use it in GitHub Desktop.
Demonstration code for post 'Going Loopy a While',
outlining the basics of 'while' loops in Java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2014. | |
*/ | |
package main.java.com.oopuniversity.basics.loops; | |
/** | |
* Created by OOPUniversity on 11/15/2014. | |
*/ | |
public class While { | |
public static void main(String [] args) { | |
while1(); | |
while2(); | |
while3(); | |
} | |
public static void while1() { | |
System.out.println("While loop 1"); | |
boolean keepRunning = true; | |
while ( keepRunning ) { | |
System.out.println("I am in a loop."); | |
keepRunning = false; | |
} | |
System.out.println("I am no longer in a loop."); | |
} | |
public static void while2() { | |
System.out.println("While loop 2"); | |
boolean keepRunning = true; | |
int runCount = 0; | |
while ( keepRunning ) { | |
System.out.println("I am in a loop."); | |
runCount = runCount + 1; | |
if ( runCount > 4 ) { | |
keepRunning = false; | |
} | |
} | |
} | |
public static void while3() { | |
System.out.println("While loop 3"); | |
int runCount = 0; | |
while ( runCount < 5 ) { | |
System.out.println("I am in a loop."); | |
runCount ++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment