Chapter 3: Control Statements: By: Kushal Jangid
Chapter 3: Control Statements: By: Kushal Jangid
By:
Kushal Jangid
Introduction
The IF Statement
Program #1 :
if 1 == 1 then
print "True!"
end
- If the code execute true then the print statement
will execute.
The IF Statement
Program #2:
x = 256
if x == 256
puts "x equals 256"
end
Output => x equals 256.
No Need of then.
The IF Statement
Program #3:
x = 256
if x == 256 then puts "x equals 256" end
Another way of writing the same statement.
The IF Statement
Program #4:
x = 256
puts "x equals 256" if x == 256
Can change the order of things, placing if after puts.
The IF Statement
Program #5:
x = 256
if x == 256: puts "x equals 256" end
Can replace : with then .
Other Operators
Program #9:
delete_record if record != 0x8ff # not equal to
if amt > 1.00 then desc = "dollars" end # greater than
desc = "cents" if amt < 1.00 # less than
if height >= 6 then print "L or XL" end # greater than or
equal to
print "shrimpy" if weight <= 100 # less than or equal to
if lang == "de"
dog = "Hund"
else
dog = "dog"
end
Thank You