Home
This chapter explores more of ruby's control structures.

case

We use the case statement to test a sequence of conditions. This is superficially similar to switch in C and Java but is considerably more powerful, as we shall see.

ruby> i=8
ruby> case i
| when 1, 2..5
| puts "1..5"
| when 6..10
| puts "6..10"
| end
6..10
nil

2..5 is an expression which means the range between 2 and 5, inclusive. The following expression tests whether the value of i falls within that range:
 Comments [Hide comments/form]
Page was generated in 0.0262 seconds