Skip to content

Instantly share code, notes, and snippets.

@stevenabrooks
Created June 9, 2013 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenabrooks/5745184 to your computer and use it in GitHub Desktop.
Save stevenabrooks/5745184 to your computer and use it in GitHub Desktop.

Write an expression that returns true by using ==

1 == 1

Write an expression that returns false using ==

1 == 2

Write an expression that returns true using != Write an expression that returns false using !=

2 != 1 1 != 1

Write an if statement with 3 different branches use != in the first branch, == in the second, and > in the third

x = 100 if x != 100 puts "It doesn't equal 100" elsif x == 5 puts "Yes it's 100" else x > 5 puts "That number is greater than 100" end

Assign a variable based on the result of an if statement

unsure

Execute code based on the result of an if statement. conditionally run puts "Hello Class" if 1 < 2

y = 1 if 1 < 2 puts "Hello class" end

Try using an if statement at the end of an expression

x = 1 puts "Hello class" if x < 2

Write an if statement that negates the or operator to return true

x = 5 y = 10 if !(x == 100 || y == 100) puts "This turns into true" end

Write an if statement that uses the and operator to create a false return

x = 1 y = 2 if x == 1 && y == 3 puts "the first part of this is true" elsif puts "this if known as 'false'" end

Write a Case Statement that checks if a variable is a vowel

Rewrite that same case statement as an if statement

Write a Case statement that has at 4 branches and a default return

Write a while loop that runs exactly 5 times

x = 0 while x < 5 puts "This loop is going to run 5 times" x += 1 end

#Write a while loop that counts from 1 to 10 and puts all odd numbers you can check if a number is odd by calling the odd? method on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment