Introduction

Consider the following code:

Demo

taxrate = 0.175  

print "Enter price (ex tax): " 
s = gets # from ww w. java  2  s.co m
subtotal = s.to_f 

if (subtotal < 0.0)  then 
  subtotal = 0.0  
end 

tax = subtotal * taxrate 
puts "Tax on $#{subtotal} is $#{tax}, so grand total is $#{subtotal+tax}"

Result

The parentheses and keyword then are optional.

However, if you were to write the following, with no line break after the test condition, the then would be obligatory:

if (subtotal < 0.0) then subtotal = 0.0 end 

Related Topic