Ruby Notes - Control Structures

language-features ruby

What does the if statement look like?

if today.saturday
	puts "Today is saturday"
elsif today.sunday
	puts "Today is sunday"
else
	puts "Go to work"
end

What does the while statement look like?

while weight < 100
	weight++
end

What are statement modifiers?

Statement modifiers are a useful shortcut if the body of an if or while statement is just a single expression.

puts "Danger" if radiation > 3000

square = square * square while square < 1000

Anything weird to remember?

  • nil is a falsy value.