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
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:
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| puts "1..5"
| when 6..10
| puts "6..10"
| end
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:

There are no comments on this page. [Add comment]