[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The LPC switch statement is very intelligent, it can also use ranges in integers:
public void wheel_of_fortune() { int i; i = random(10); // Get a random number 0 - 9 // Strictly speaking, this local variable isn't // necessary, it's just there to demonstrate the // use and make things clearer. I could have // switched on 'random(10)' directly instead if // I had wanted to. switch (i) { case 0..4: write("Try again, sucker!\n"); break; case 5..6: write("Congrats, third prize!\n"); break; case 7..8: write("Yes! Second prize!\n"); break; case 9: write("WOOOOPS! You did it!\n"); break; default: write("Someone has tinkered with the wheel... Call 911!\n"); break; } } |