English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

ex::IF (CONDITION)
statement
statement
ENDIF

Q1) if we have several if's we add several endif's?
that is::
IF (condi)
statmt
IF (cond)
Stmt
IF (cd)
st
END IF (once or thrice??)

Q2)
(example is given on a site why does the first one use several ENDIF and the other only one
Example1::
IF mark >= 80 THEN
grade = "A"
comment = "Excellent"
ELSE
IF mark >= 70 THEN
grade = "B"
ELSE
IF mark >= 60 THEN
grade = "C"
ELSE
IF mark >= 50 THEN
grade = "D"
ELSE
grade = "N"
comment = "Poor"
ENDIF
ENDIF
ENDIF
ENDIF


Example2:::

IF mark >= 80 THEN
grade = "A"
comment = "Excellent"
ELSE IF mark >= 70 THEN
grade = "B"
ELSE IF mark >= 60 THEN
grade = "C"
ELSE IF mark >= 50 THEN
grade = "D"
ELSE
grade = "N"
comment = "Poor"
ENDIF

2007-07-28 22:50:51 · 3 answers · asked by Doopy D 1 in Computers & Internet Programming & Design

3 answers

Assuming that Pseudocode1 is not some particular training language, your questions depend on the syntax of the languages involved.

(Q1) Typically, an ENDIF construct is needed for each IF to clarify flow and nesting. However, other constructs between the pair may include ELSEIF and ELSE (see Q2)

(Q2) in example 1 all of the ELSE constructs are used as standalone having no "ELSEIF" construct. This is:
IF {} ELSE {} ENDIF
which stacks nested as:
IF {} ELSE {IF {} ELSE {IF {} ELSE {} ENDIF} ENDIF} ENDIF{}
note that other stacking/nesting is also possible, such as:
IF {IF {} ELSE {} ENDIF} ELSE {} ENDIF

while the example 2 syntax appears to use "ELSEIF" constructs as:
IF {} ELSEIF {} ELSEIF {} ... ELSE {} ENDIF
which does not require, but does allow stacking nesting as desired.
The syntax of various languages may have no elseif construct (very old) or may require elseif as a single word or allow the else if to be separated. Some languages obviate the question through non-verbose blocking delimiters such as {} pairs and the ; ending, which eliminate the need for an explicit ENDIF construct.

2007-07-29 00:01:00 · answer #1 · answered by oldguy 4 · 3 0

If you have several IFs then you should have an ENDIF for each IF. This shows the logic flow.
Consider
IF test1
IF test2
DO something
ENDIF
DO something
ELSE
DO something
ENDIF.

or

IF test1
IF test2
DO something
ELSE
DO something
ENDIF
ENDIF.

Your second example is a way of showing a switch or case statement. The ELSEIF gives this away. Because it is one case statement there is only one ENDIF.

I hope this helps.

2007-07-29 05:59:33 · answer #2 · answered by AnalProgrammer 7 · 0 0

For getting homework help there are better websites . Check http://getafreelnacer.com/ for example.

2007-07-29 09:40:35 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers