-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path03-control.rb
More file actions
59 lines (49 loc) · 909 Bytes
/
Copy path03-control.rb
File metadata and controls
59 lines (49 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# if-statement
if true
puts "it's true"
end
# if-else statement
happy = false
if happy # only the boolean false and nil are false, everything else is true
puts "Smile :)"
else
puts "Still Smile :)"
end
# if-else-if statment
age = 42
if age < 21
puts "Still a child"
elsif age <= 35
puts "Young Adult"
elsif
puts "Adult"
end
# you can use this other form
puts "it's true again!" if true
rainy = false
# if not rainy
unless rainy
puts "it is not raining outside!"
end
room_temp = 67
# case statement with numbers
case room_temp
when 69
puts "Room is a little warm but okay"
when 68
puts "Room feels just right"
when 67
puts "Room is a little chilly but okay"
else
puts "Room is too hot or too cold"
end
season = "spring"
# case statement with string
case season
when "spring"
puts "Yay Basketball!"
when "fall"
puts "Yay Football"
else
puts "Yay Baseball"
end