Introduction

Consider the following code:

Demo

taxrate = 0.175  

print "Enter price (ex tax): " 
s = gets # from w ww  .  j  a va2s .  c om
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