Conditionals
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Conditionals

on

  • 674 views

Conditionals

Conditionals

Statistics

Views

Total Views
674
Views on SlideShare
674
Embed Views
0

Actions

Likes
0
Downloads
15
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • Unlike some languages with the 0 and empty string\n! Binds more tightly than than the “not” keyword so you do need parentheses for example 1, but don’t need parentheses for example 2\n
  • Conditionals are key to being able to make decisions in a program\n\nleft looks like every other language\n\nparentheses are optional in ruby \nmake sure to do ==, = is an assignment, == is a conditional test\n\nExplain puts\n\nright is a little different…people in ruby don’t like to type…english readable\nA statement modifier lets you move control structures at the end of an expression.\n
  • Conditionals are key to being able to make decisions in a program\n\nleft looks like every other language\n\nparentheses are optional in ruby \nmake sure to do ==, = is an assignment, == is a conditional test\n\nExplain puts\n\nright is a little different…people in ruby don’t like to type…english readable\nA statement modifier lets you move control structures at the end of an expression.\n
  • \n
  • Unless can be awkward, especially with else. Usually you’ll want to use if for conditionals with else clauses.\n Occasionally unless is more readable:\n unless something is nil\n
  • \n
  • \n
  • \n
  • \n
  • \n

Conditionals Presentation Transcript

  • 1. CONDITIONALS Sarah Allen
  • 2. TRUTH• Truth: Everything is true except for: – false – nil• Therefore – 0 is true – “” is true
  • 3. CONDITIONALS: IFif age > 17 puts “can vote” Statement Modifiers:end do_something if x == 4 Other Syntax: if x == 4 then do_something endif age > 17 puts “can vote”else puts “attends school”end
  • 4. CONDITIONALS: IFif age >= 21 puts “can drink”elsif age > 17 puts “can vote”else puts “too young”end
  • 5. CHECKING FOR FALSEif !(name == “superman”) …if not (name == “superman”) …
  • 6. UNLESS• “unless” provides us with another way of checking if a condition is false: unless human status = "superhero" end status = "superhero" unless human
  • 7. CASEcase superhero when "superman" city = "metropolis" when "batman" city = "gotham_city" else city = "central_city"end
  • 8. CASE REFACTORINGcity = case superhero when "superman" "metropolis" when "batman" "gotham_city" else "central_city"end
  • 9. CASEcase num when 1 puts "one" when 2..5 puts "that is small" else puts "pretty big"end
  • 10. CASEcase name when "Sarah" puts "awesome" when /Mr.*/ puts "formal guy" else puts "whatever"end
  • 11. CASEcase args when String puts "Got a String" when Array puts "Got an Array” when Hash puts "Got a Hash"end