learn_ruby_ch3_pt1 Flashcards
1
Q
If statement equals (x = 1)
A
x = 1
if x == 1 then
print “true”
end
2
Q
Single line if with puts (x = 256)
A
x = 256
puts “x equals 256” if x == 256
3
Q
If with “and” logical operator
ruby = "nifty" prog = "fun"
A
ruby = "nifty" prog = "fun"
if ruby == “nifty” && prog == “fun”
puts “Keep programming!”
end
or replace && with “and”
replace || with “or”
4
Q
If with “not” logical operator (queue)
A
queue = false
if !queue then print “The queue is empty.” end
or
if not queue then print “The queue is empty.” end
5
Q
If with an else (queue)
A
if queue pr = true else pr = false end
or
if queue then
6
Q
An else if combo using symbols
lang = :es
A
lang = :es if lang == :en print "dog" elsif lang == :es print "perro" elsif lang == :fr print "chien" else puts "No language set" end