Skip to content

Commit

Permalink
Assigning logic statement to variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mindaslab committed Jun 7, 2014
1 parent 4833118 commit ff6aedc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions case_when_2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# case_when_2.rb
# This program spells from one to five

print "Enter a number (1-5):"
a = gets.to_i
spell = String.new

spell = case a
when 1
"one"
when 2
"two"
when 3
"three"
when 4
"four"
when 5
"five"
else
spell = nil
end

puts "The number you entered is "+spell if spell
9 changes: 9 additions & 0 deletions max_of_nums_with_if.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# max_of_nums_with_if.rb

a,b = 3,5
max = if a > b
a
else
b
end
p "max = "+max.to_s
11 changes: 11 additions & 0 deletions max_of_nums_with_if_many_statements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# max_of_nums_with_if_many_statements.rb

a,b = 3,5
max = if a > b
a+b
a
else
a-b
b
end
p "max = "+max.to_s

0 comments on commit ff6aedc

Please sign in to comment.