In this lesson,
we're going to talk about Logic Control.
Now, Logic Control is used to provide conditions
based on different logical tests.
This may be a test of a Boolean operator,
an arithmetic operator, or a string operator.
Let's take a look at each of these
and how we can use different logical conditions
to migrate the flow of a program
that we write in our scripts.
First, let's consider the following example.
If x = 1, THEN OUTPUT "The statement was true,"
ELSE OUTPUT "The statement was false."
ENDIF.
What this code is saying is we're doing basically,
an IF, THEN, ELSE statement,
if this condition is true,
and remember in Boolean 1 is true, 0 is false,
then we're going to say, "The statement was true."
Otherwise, we're going to output, "The statement was false".
This is a very simple way to test a condition
and get a Boolean value of either true or false.
Second, we can do things with arithmetic.
This might be something like, IF balance less than 10.00,
THEN, OUTPUT "The account has insufficient funds."
ELSE, OUTPUT "The account has at least $10."
ENDIF.
Essentially, this is simply testing,
do you have enough money in your bank account
if the minimum balance required is at least $10?
This is a simple arithmetic operation
and we're just using a less-than sign.
Similarly, you can use a greater-than sign
or an equal sign if you'd like as well.
Another test we can do is based on string values.
So IF x = "Jason" THEN
OUTPUT "The user was Jason."
ELSE OUTPUT "The user was someone else."
ENDIF.
Again, this is a very simple case
where we're simply testing the value of the variable
and seeing does it match the string "Jason."
Now note, these conditional checks
are going to be case sensitive.
So if your x was equal to lowercase "j-a-s-o-n,"
this would not be a true statement,
and you would get the output that the user was someone else.
A final thing we want to look at here
is how we can combine things to do additional checks.
For example, IF minutes greater than 120 THEN
OUTPU "You have studied for 2 hours.
ELSE IF minutes greater than 60, THEN
OUTPUT 'You should continue to study for another hour."
ELSE OUTPUT "You need to study for at least 2 hours today."
ENDIF.
What this is saying is we're going to test
the first condition, are the minutes greater than 120?
If they are, then we're going to output,
"You have studied for 2 hours," and stop right there.
If they're not, we're going to go
to the first ELSE condition.
Now, in that first ELSE condition,
we have another condition.
"If the minutes are greater than 60,"
then we would output,
"You should continue to study for another hour."
If they're not, we're going to go to its ESLE condition,
which says, "You need to study for at least 2 hours today."
So if your minutes value
is set at 75 going into this condition,
it's going to choose,
"You should continue to study for another hour,"
because you don't have at least 120 minutes,
but you do have more than 60.
If you had 45 minutes,
that would put you in the third condition.
"You need to study for at least 2 hours today,"
because you haven't even reached the hour point.
That is what we're doing
in this nested IF that we're using,
in this, IF ELSE, IF ELSE ENDIF condition.
Now the last thing I want to mention
is that when you're doing these different conditions,
you can actually combine them as well.
For example, I can combine Boolean conditions
with arithmetic operations.
Take a look at this one.
IF (minutes greater than 60 AND minutes less than 120,) THEN
OUTPUT, "You have between 60 and 120 minutes completed.'
ELSE, OUTPUT "You have more than 120 minutes
or less than 60 minutes completed."
ENDIF.
Notice, I'm testing the connection inside those parentheses.
The minutes are greater than 60,
and the minutes are less than 120.
This tells me I'm somewhere between 61 and 119 minutes.
By using these different types of conditions,
you can start excluding or including different areas.
For example, if I wanted to find anybody
who had more than 120 minutes and less than 60 minutes,
that might tell me people
who are over-studying or understudying,
I can do that by using minutes less than 60,
and minutes greater than one 20.
This will allow you to do these type of logical conditions
and testing conditions using ANDs, ORs, and NOT conditions,
which are all Boolean operations.