Loop Example: Termination
Sometimes we don’t know how many times the body of a loop will be executed:
import java.Math;
// flip a coin until heads is flipped.
public static void flipcoin() {
while (Math.random() < 0.5)
{
System.out.println(“Tails!”);
}
}
Previous slide
Next slide
Back to first slide
View graphic version