This FreeBASIC tutorial is the third in the Easy FreeBASIC tutorial series. To use this tutorial, copy and paste each code example into your FreeBASIC IDE and test it out.
if 2 + 2 = 4 then print "2 + 2 does equal 4!"
sleep
end
An if statement will execute the code after then if the expression after if is true.
if 2 + 2 = 5 then print "This is false"
sleep
end
An if statement will not execute the code after then if the expression is false.
if 5 then print "It's five!"
sleep
end
The expression can be a single number
dim someInteger as Integer = 10
if someInteger then print "It's 10!"
sleep
end
Variables can be used as expressions.
if 1 then print "True! (1)"
if 5 then print "True! (5)"
if 0 then print "False! (0)"
sleep
end
In an if statement 0 is false and anything except 0 is true.
if 5 = 5 then print "5 does equal 5."
if "text" = "text" then print "text equals text"
sleep
end
The equals sign can be used to compare numbers and strings. If they are the same, the expression is true. If they are not, it is false.
if "someString" = 5 then
print "This is never seen because of errors"
end if
sleep
end
You cannot compare a number and a string in an if statement.
if 2 < 5 then print "2 is less than 5"
sleep
end
The less than symbol ( < ) can be used to compare numbers.
if 5 > 2 then print "5 is greater than 2"
sleep
end
The greater than symbol ( > ) can be used to compare numbers.