Changes

Jump to: navigation, search

Ruby Flow Control

17 bytes added, 14:49, 31 March 2009
no edit summary
In the above outline, the ''expression'' is a logical expression that will evaluate to either true or false. If the expression is true, then the code represented by ''ruby code'' will execute. Otherwise the code is skipped. The ''end'' statement marks the end of the ''if'' statement.
Let's look at an example:
</pre>
As shown in the above example the code block following the ''if'' statement is executed when the expression is evaluated to be true (i.e . the customerName variable contains the string "Fred") and the script after the ''else'' statement is executed when the customerName does not match the string "Fred".
''elsif'' structures take the ''if ... else ...'' concept a step further to implement ''if ... else ... if ... else ...'' structures. For example:
== Summary ==
In this chapter of [[Ruby Essentials]] we have explored basic control structures with which allow us to build decision making logic into our Ruby programs. In the following chapter we will look at a more advance advanced conditional structure, [[The Ruby case Statement]].

Navigation menu