Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 813 Bytes

flow-control.md

File metadata and controls

39 lines (29 loc) · 813 Bytes

FLOW CONTROL

true and false, if and else.

true and false are unique objects (technically instances of TrueClass and FalseClass)

They are the result of comparison operators

  • > Greater than?
  • >= Greater than or equal to?
  • < Less than?
  • <= Less than or equal to?
  • == Equal?
  • != Not equal?
1 > 0
# => true

"hello" == "hello"
# => true

Conditionals

if and else allow you to control the flow of your program. The concept is pretty simple, read the following, you should be able to get a good idea of what the program will do

puts "Hey! What’s your name?"
response = gets.chomp

if response.downcase == 'computer'
  puts "Weird, that's my name too. Small world!"
else
  puts "Wacky name!"
end

puts "Well, it was nice to meet you #{response}."