OnJava8-Examples/control/WhileTest.java

30 lines
720 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// control/WhileTest.java
2015-06-15 17:47:35 -07:00
// <20>2015 MindView LLC: see Copyright.txt
// Demonstrates the while loop.
public class WhileTest {
static boolean condition() {
boolean result = Math.random() < 0.99;
System.out.print(result + ", ");
return result;
}
public static void main(String[] args) {
while(condition())
System.out.println("Inside 'while'");
System.out.println("Exited 'while'");
}
2015-09-07 11:44:36 -06:00
}
/* Output: (First and last 5 Lines)
2015-06-15 17:47:35 -07:00
true, Inside 'while'
true, Inside 'while'
true, Inside 'while'
true, Inside 'while'
true, Inside 'while'
________...________...________...________...________
true, Inside 'while'
true, Inside 'while'
true, Inside 'while'
true, Inside 'while'
false, Exited 'while'
2015-09-07 11:44:36 -06:00
*/