Ruby Flow Control

From Techotopia
Revision as of 19:04, 19 November 2007 by Neil (Talk | contribs) (New page: One of the most powerful features of Ruby (and every other programming or scripting language for that matter) is the ability to build intelligence and logic into code. This is achieved thr...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

One of the most powerful features of Ruby (and every other programming or scripting language for that matter) is the ability to build intelligence and logic into code. This is achieved through the use of control structures which decide what code is executed based on logical expressions.

In this chapter of Ruby Essentials we will look at how such control structures are built.

The Ruby if Statement

The if statement is the most basic of the Ruby control structures. if statements simply specify a section of Ruby script to be executed when a specified criteria is met. The syntax for an if statement is as follows:

if expression then

  ruby code

end