Advertisement
karlakmkj

unless Keyword

Sep 1st, 2021
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.37 KB | None | 0 0
  1. # 2 ways to use unless keyword - opposite of if expression  
  2. hungry = false
  3.  
  4. unless hungry  #check if something is false
  5.   puts "I'm writing Ruby programs!"   #when not hungry (ie. false)
  6. else
  7.   puts "Time to eat!" #when hungry (ie. true)
  8. end # always end the loop
  9.  
  10. problem = false
  11. print "Good to go!" unless problem  # statement will be printed since problem is false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement