Iterative Control-Loop Assignment Help

Assignment Help: >> Control Structures - Iterative Control-Loop

Iterative Control:

An Iterative statement is a set of statements which are performed a number of times depending on the value in the LOOP statement. There are three fundamental forms of LOOP statements which are given below:

  • LOOP
  • WHILE LOOP
  • FOR LOOP

 

LOOP

The  easiest  form  of  LOOP  statement  is  the  basic  (  or  infinite)  loop,  that  encloses  a sequence of statements among the keywords LOOP and END LOOP. The syntax is given below.

Syntax

LOOP Sequence_of_statements; End LOOP.

With  every  Iteration  of  the  loop the  sequence  of  statements  is  executed, the  control resumes at the top of the loop. The given example describes the execution of the LOOP statement.

Example

DECLARE

a NUMBER:=10;

BEGIN

LOOP DBMS_OUTPUT.PUT_LINE(a);

END LOOP;

END;

The output leads to an error. Since the number of times the loop must be executed is not specified and it goes for an infinite loop. Sequentially to terminate the loop a few form of termination statement is needed. The EXIT statement is used to perform this operation.

Example

DECLARE

A NUMBER:=&A;

BEGIN

LOOP DBMS_OUTPUT.PUT_LINE(A);

a:=a+1;

IF a > 20 THEN

EXIT;

End if;

END LOOP;

END;

Till the value crosses 20 the loop is executed and once the value for the variable reaches to 20 the loop is terminated by using the EXIT statement.  This EXIT statement can be additionally simplified through the usage of EXIT_WHEN statement.

FOR-LOOP Iteration schemes
While loop
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd