-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlooping_logic_chris_pine5.rb
61 lines (48 loc) · 1.11 KB
/
looping_logic_chris_pine5.rb
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
60
61
#looping
#keep repeating something, with an end point otherwise will never stop!
command = " "
while command != "bye"
puts command
command = gets.chomp
end
puts "Come again soon!"
#what is wrong about this loop?
#Adding more logic to branching program
#version 1
puts "Hello, what\'s your name?"
name = gets.chomp
puts "Hello, #{name}."
if name == "Charlotte"
puts "What a lovely name!"
else
if name == "Felipe"
puts "What a lovely name!"
end
end
#DRY rule
#version 2
puts "Hello, what\'s your name?"
name = gets.chomp
puts "Hello #{name}."
if (name == "Charlotte" or name == "Felipe")
puts "What a lovely name!"
end
#always good to use () when using the logical operators
#or means "one or the other, or both" - slight different
#version 1
iAmChris = true
iAmPurple = false
iLikeFood = true
iEatRocks = false
puts (iAmChris and iLikeFood)
puts (iLikeFood and iEatRocks)
puts (iAmPurple and iLikeFood)
puts (iAmPurple and iEatRocks)
puts
puts (iAmChris or iLikeFood)
puts (iLikeFood or iEatRocks)
puts (iAmPurple or iLikeFood)
puts (iAmPurple or iEatRocks)
puts
puts (not iAmPurple)
puts (not iAmChris )