Chapter 8 Iterative Control


Lab 8.1 Self-Review Answers

A5:

Questions

Answers

Comments

1)

C

If there is no EXIT condition specified, a simple loop becomes an infinite loop. In other words, a sequence of statements will be executed an infinite number of times because there is no statement specifying when the loop must terminate.

2)

B

As soon as the EXIT statement is encountered , the loop is terminated .

3)

A

As long as the EXIT condition does not evaluate to TRUE, the control is never transferred to the EXIT statement. This will prevent a loop from terminating. For example,

 IF x > 5 THEN    EXIT; END IF; 

In this case, the EXIT condition is a test condition of the IF statement. When the test condition of the IF statement evaluates to FALSE or NULL, the control is passed to the first executable statement after END IF.

4)

C

Once EXIT statement is executed, the control is transferred to the first executable statement after END LOOP.

5)

B

An EXIT condition of a simple loop is located inside the body of the loop. Therefore, the loop will always execute partly before the EXIT condition is evaluated.


Lab 8.2 Self-Review Answers

A5:

Questions

Answers

Comments

1)

A

Before a WHILE loop is executed, its test condition is evaluated. If the test condition yields FALSE, the WHILE loop is unable to execute.

2)

C

If a test condition always evaluates to TRUE, the WHILE loop is unable to terminate. As a result, it executes infinite number of times.

3)

B, C

 

4)

A

You will recall that a test condition must evaluate to FALSE or NULL for a WHILE loop to terminate. On the other hand, the EXIT condition must evaluate to TRUE. Thus, if the EXIT condition evaluates to TRUE before the test condition evaluates to FALSE, the WHILE loop terminates prematurely.

5)

A

If a test condition of a WHILE loop never evaluates to TRUE, the loop does not execute at all.


Lab 8.3 Self-Review Answers

A5:

Questions

Answers

Comments

1)

B

For the first iteration of the loop, the value of the loop counter is equal to the lower limit. For the second iteration of the loop, the value of the loop counter is implicitly incremented by 1. At this point, the value of the loop counter does not satisfy the range specified by the lower limit and the upper limit, so the loop terminates. For example,

 BEGIN    FOR i IN 1..1 LOOP       DBMS_OUTPUT.PUT_LINE ('i = 'i);    END LOOP; END; /  i = 1   PL/SQL procedure successfully completed.  

2)

A

The loop counter is unable to satisfy the range specified by the lower and upper limits.

3)

C

The loop counter is implicitly defined by the loop construct. As a result, it does not exist anywhere outside the loop.

4)

C

 

5)

B

The loop counter is initialized to the upper limit, and it is decremented by 1 for each iteration of the loop.


Lab 8.4 Self-Review Answers

A5:

Questions

Answers

Comments

1)

C

 

2)

B

Loop labels are optional feature and are used to improve readability.

3)

B

 

4)

B

It is considered bad programming practice to use the same name for different variables. When the same name is used for the loop counters, you are unable to reference the outer loop counter in the body of the inner loop. In order to differentiate between two variables having the same name , you must use loop labels when the variables are referenced.

5)

B

You must use loop labels only when outer and inner loop counters have the same name and you want to reference the outer loop counter in the inner loop. In other cases, it is not necessary to use a loop label when referencing the loop counter.




Oracle PL[s]SQL by Example
Oracle PL[s]SQL by Example
ISBN: 3642256902
EAN: N/A
Year: 2003
Pages: 289

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net