Chapter 10 Control Structures

This chapter discusses Ruby’s control structures. Control structures are expressions with values.

case

Use the case statement to test a sequence of conditions.

Syntax:

case expr
    [when expr [, expr]...[then]
      expr..]..
    [else
      expr..]
    end

while

The while statement is a repeated if.

Syntax:

expr while expr

if

The if expression is used for conditional execution.

Syntax:

expr if expr

unless

The unless expression is used for reverse conditional statements.

Syntax:

unless expr [then]
      expr...
    [else
      expr...]
    end

and

Syntax:

expr && expr
    expr and expr

or

Syntax:

expr || expr
    expr or expr

not

Syntax:

! expr
    not expr

  • Currently 2.98/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
  Flag Inappropriate Content 0 comments