ruby-for-beginners icon indicating copy to clipboard operation
ruby-for-beginners copied to clipboard

Example for conditionals

Open svenfuchs opened this issue 8 years ago • 0 comments

The question what a more real-world example for an if statement with several branches could be came up, and the following was found:

color = :black

if color == :red
  puts "stop!"
elsif color == :yellow
  puts "stop!"
elsif color == :red_yellow
  puts "get ready"
elsif color == :green
  puts "go!"
else
  raise "AMPEL KAPUTT"
end

Also, unless doesn't seem to be mentioned?

svenfuchs avatar Dec 18 '17 19:12 svenfuchs