Re: Use of If/Then/Else
[Prev][Next][Index][Thread]
Re: Use of If/Then/Else
On Thu, 14 Nov 1996, Ian Turner wrote:
> What is the syntax of the IF command (and friends)?
> I understand the concept but have lost my manual and can't seem to get
> the syntax right.
> --
> - Ian Turner (Vectro)
> Turner Computers
>
>
If statement provides a conditional loop. It is uses to test and then
perform a function because of this test. If the test passes, then the
following instruction is carried. If not, then it is the next instruction.
For example:
Input "Any number please? ", NUM
If NUM < 0
-NUM\->\NUM
Sum=y1+NUM
If NUM=3 and y1 =4, Then Sum =7 If NUM=-3, then the sum is still 7.
A Then statement is used to carry out an if statement for more than one
line. This case requires a End statement to finish the loop.
Input "Any number please? ", NUM
If NUM < 0
Then
-NUM\->\NUM
NUM-3\->\RESULT
y2=RESULT^NUM
End
Sum=y1+NUM+y2
Here if NUM was positive then the instructions between Then and End would
be skipped over. If not, then these instructions are carried through.
An else statement is used within the If-Then statement to provide two
conditions in the loop one if the test is true and then if the test is false.
Input "Any number please? ",NUM
If NUM < 0
Then
-NUM\->\NUM
NUM-3\->RESULT
y2=RESULT^NUM
Else
NUM+2\->\RESULT
y3=ln RESULT + NUM^3
End
Sum=y1+NUM+y2+y3
If NUM were negative, then instructions between Then and Else would be
carried out, but, if NUM was not negative, then only the instructions
between Else and End would carried out.
I hope this helps
References: