Wednesday, 10 August 2011

Conditional Statements

0 comments
 
What Are Conditional Statements?
Suppose you want to protect your program with password.
You ask from the user to enter the password.
If the password is correct - you want to let the user in, if not - you want to end the program.

To do this, you have to use conditional statement because
the code you will execute (let the user in or end the program) is
depend on what is the password that the user has entered.

One of the basics of Conditional statement are Boolean variables.
Boolean variables are commonly used in programming,
and you have to understand them before continuing with conditional statements.

Boolean VariablesAs we learnt, String variables store text, and
Integer Variables Store numbers.
Boolean variable stores one of the following constant values:
"True", or "False".

For example:

Dim Kuku As Boolean
Kuku = True
Dim YoYo As Boolean
YoYo = False


What are the True and False stand for?
They are the result of every "Boolean expression".

Boolean Expressions 
Boolean expression is like a question that
the answer to it is "True" or "False"

For example:
Is 4 Plus 6 is 10? True
Is 2 bigger than 4? False

But the question
How much is 4 Plus 6?
Is not a boolean expression, because its answer is 10 (and not True or False)

Examples Of Boolean ExpressionsThe following code:

Dim ABC As Boolean
ABC = (3 > 4)
Print ABC


Will print "False" on the form.
The value of the boolean expression 3 > 4
is "False", because 3 is not greater than 4.


The following code:

Dim ABC As Boolean
ABC = ("abf" = "abf")
Print ABC


Will print "True" on the form.
The value of the boolean expression "abf" = "abf"
is "True", because "abf" is equal to "abf"


The following code:

Dim ABC As Boolean
Dim A As Integer
Dim B As Integer
A = 1
B = 2
ABC = (A + 1 = B)
Print ABC


Will print "True" on the form,
because the value of the boolean expression (A + 1 = B) is "True".


In Boolean expressions you can use the following signs:


= Equal to
<> Not Equal to
> Greater than
< Smaller than
>= Greater than or Equal to
<= Smaller than or Equal to

Leave a Reply