Pagini

marți, 12 martie 2013

Section 4 Lesson 5: Iterative Control: Nested Loops


Iterative Control: Nested Loops

 1.  What statement allows you to exit the outer loop at Point A in the following block?
DECLARE
 v_outer_done CHAR(3) := 'NO';
 v_inner_done CHAR(3) := 'NO';
BEGIN
 LOOP -- outer loop
  ...
   LOOP -- inner loop
   ...
   ... -- Point A
   EXIT WHEN v_inner_done = 'YES';
   ...
  END LOOP;
  ...
  EXIT WHEN v_outer_done = 'YES';
  ...
 END LOOP;
END;
(1) Points
     
    EXIT AT v_outer_done = 'YES';
    EXIT WHEN v_outer_done = 'YES'; (*)
    WHEN v_outer_done = YES EXIT;
    EXIT <<outer loop>>;
     
  2.  Which one of these statements about using nested loops is true? (1) Points
     
    All the loops must be labelled
    The outer loop must be labelled, but the inner loop need not be labelled
    The outer loop must be labelled if you want to exit the outer loop from within the inner loop (*)
    Both loops can have the same label
     
  3.  What will be displayed when the following block is executed?
DECLARE
  x NUMBER(6) := 0 ;
BEGIN
  FOR i IN 1..10 LOOP
    FOR j IN 1..5 LOOP
    x := x+1 ;
    END LOOP;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE(x);
END;
(1) Points
     
    5
    10
    15
    50 (*)
     
  4.  When the following code is executed, how many lines of output will be displayed?
BEGIN
  FOR i IN 1..5 LOOP
    FOR j IN 1..8 LOOP
      DBMS_OUTPUT.PUT_LINE(i || ',' || j);
    END LOOP;
    DBMS_OUTPUT.PUT_LINE(i);
  END LOOP;
END;
(1) Points
     
    80
    45 (*)
    14
    41
     
  5.  What type of loop statement would you write for Point A?
BEGIN
  FOR v_outerloop IN 1..3 LOOP
    -- Point A
     DBMS_OUTPUT.PUT_LINE('Outer loop is:'||v_outerloop||
     ' and inner loop is: '||v_innerloop);
     END LOOP;
  END LOOP;
END;
(1) Points
     
    WHILE v_innerloop <=5 LOOP
    FOR v_innerloop 1..5 LOOP (*)
    LOOP
    WHILE v_outerloop<v_innerloop LOOP
     
  6.  Look at the following code:
DECLARE
  v_blue NUMBER(3) := 0;
  v_red NUMBER(3) := 0;
BEGIN
<< blue >> LOOP
  v_blue := v_blue + 1;
  EXIT WHEN v_blue > 10;
  << red >> LOOP
    v_red := v_red + 1;
    EXIT WHEN v_red > 10;
     -- Line A
  END LOOP red;
END LOOP blue;
END;

What should you code at Line A to exit from the outer loop?
(1) Points
     
    EXIT;
    EXIT red;
    EXIT <<blue>>;
    EXIT blue; (*)

Niciun comentariu:

Trimiteți un comentariu