For-loop -iterative control, PL-SQL Programming

FOR-LOOP

While the number of iterations through a WHILE loop is unknown till the loop completes, then the number of iterations through a FOR loop is known before the loop is entered. The FOR loops iterate over a particular range of integers. The range is the part of an iteration scheme that is enclosed by the keywords FOR and LOOPS. A double dot (..) serve as the range operator. The syntax is as shown below:

FOR counter IN [REVERSE] lower_bound..higher_bound LOOP
sequence_of_statements
END LOOP;


The range is computed when the FOR loop is first entered and is never re-evaluated.



As the next illustration shows, the series of statements is executed once for each integer in the range. After each of the iteration, the loop counter is incremented.

FOR i IN 1..3 LOOP -- assign the values 1,2,3 to i
sequence_of_statements -- executes three times
END LOOP;


The following illustration shows that if the lower bound equals the higher bound, the series of the statements is executed once:

FOR i IN 3..3 LOOP -- assign the value 3 to i
sequence_of_statements -- executes one time
END LOOP;

Posted Date: 10/3/2012 5:57:10 AM | Location : United States







Related Discussions:- For-loop -iterative control, Assignment Help, Ask Question on For-loop -iterative control, Get Answer, Expert's Help, For-loop -iterative control Discussions

Write discussion on For-loop -iterative control
Your posts are moderated
Related Questions
Multiple Assignment- SQL SQL supports multiple assignment to local variables and also applies multiple assignment semantics in SET clauses of UPDATE statements, but does not

Using a join on 3 tables, select 5 columns and 10 rows from the 3 tables without the use of a Cartesian product Query: SELECT E.LAST_NAME, E.FIRST_NAME, S.BUILDING, S.BRAN

Write a pl/sql block that declares and uses cursors with parameters. In a loop, use a cursor to retrieve the department number and the department name from the departments table

LONG and LONG RAW You use the LONG datatype to store the variable-length character strings. The LONG datatype is such as the VARCHAR2 datatype, except that the maximum length o

Package Specification The package specifications contain the public declarations. The scopes of these declarations are local to your database representation and global to the

Authorisations - Privileges As relational theory is silent on the issue of authorisation, it offers nothing with which SQL's vast edifice in support of what it calls privilege

Parameter SELF in pl/sql The MEMBER methods recognize a built-in parameter named SELF that is an instance of the object type. Whether declared explicitly or implicitly, it is

Blocks: The fundamental program unit in the PL/SQL is the block. The PL/SQL block is defined by the keywords BEGIN, DECLARE, EXCEPTION, and END. These keywords partition the b

ROWID The ROWID returns the rowid (binary address) of a row in the database table. You can use the variables of the type UROWID to store rowids in a readable format. In the il

Table Comparison - SQL The following definitions for relation comparisons: Let r1 and r2 be relations having the same heading. Then: r1 ⊆ r2 is true if every tuple of r1