0% found this document useful (0 votes)
28 views

In This Lecture, We Will Discuss : Flow of Control

This lecture discusses different types of flow control in Ruby including if/else statements, case expressions, while and for loops. It also covers the differences between true and false values as well as the triple equals operator. Key topics are flow control syntax without parentheses or curly braces, and using end to close blocks, along with the various ways to iterate over data in Ruby.

Uploaded by

JITENDRA TIWARI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

In This Lecture, We Will Discuss : Flow of Control

This lecture discusses different types of flow control in Ruby including if/else statements, case expressions, while and for loops. It also covers the differences between true and false values as well as the triple equals operator. Key topics are flow control syntax without parentheses or curly braces, and using end to close blocks, along with the various ways to iterate over data in Ruby.

Uploaded by

JITENDRA TIWARI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

In this lecture, we will discuss…

▪  Flow of Control
▪  if / elsif / else
▪  case
▪  until / unless?
▪  while / for

▪  What is true and what is false?

▪  What in the world is === ?


Flow of Control
▪  if, unless, elsif, else
▪  No parentheses or curly braces
▪  Use end to close flow control block
Flow of Control
▪  while, until
Flow of Control: Modifier Form
▪  if, unless, while, until – on the same line as the
statement
True / False
▪  false and nil objects are false

▪  Everything else is true!


Triple Equal
▪  Triple Equal: ===
▪  “Equal” in its own way
▪  Sometimes it’s not about being exactly equal
Case Expressions

▪  Two “flavors”
1.  Similar to a series of “if” statements
2.  Specify a target next to case and each when clause
is compared to target

▪  === is called the case equality operator because it is


used in precisely this case!

▪  No fall-through logic

7
Case Expressions
For Loop
▪  Hardly used

▪  each / times preferred

Range data type

9
Summary
▪  Lots of options for flow of control
▪  Modifier form is an interesting way to be very expressive
▪  Non-nil and non-false values are always true

What’s next?

▪  Functions / Methods

You might also like