learn_ruby_ch3_pt1 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

If statement equals (x = 1)

A

x = 1
if x == 1 then
print “true”
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Single line if with puts (x = 256)

A

x = 256

puts “x equals 256” if x == 256

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

If with an else (queue)

A
if queue
  pr = true
else
  pr = false
end

or
if queue then

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly