top of page

Ruby Intro Tutorial - Control flow with If, Else, and Elsif

The best way to make your app dynamic is with some conditions that resolve various decisions made by the end user. We call this Control Flow. Below is a quick lesson on Control Flow with If, Else, and Elsif statements. Let's create a small program that compares the name of two people and tells us whose name has more characters in it. Look at the Source Code below. First we create two String variables and initialize them. Then after that we will use the .length helper method on each String to compare the character length of each String. All Strings are objects in Ruby, so this method (and many more) are built in. Finally, We will print out a result for each of the three conditions (see below). Note: Comments in Ruby are very different compared to other programming languages. See below on how we do Multi and Single line comments.

Now give it a try! Write your own program that compares something like the ages of two people, or even one that takes user input.

Featured Posts
Check back soon
Once posts are published, you’ll see them here.
Recent Posts
Archive
Search By Tags
No tags yet.
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page