Mutual recursion, PL-SQL Programming

Assignment Help:

Mutual Recursion

The Subprograms are mutually recursive if they directly or indirectly call each other. In the illustration below, the Boolean functions odd & even, that determine whether the number is odd or even, call each other straightly. The forward declaration of odd is essential as even calls odd, that is not yet declared when the call is made.

FUNCTION odd (n NATURAL) RETURN BOOLEAN; -- forward declaration

FUNCTION even (n NATURAL) RETURN BOOLEAN IS

BEGIN

IF n = 0 THEN

RETURN TRUE;

ELSE

RETURN odd(n - 1); -- mutually recursive call

END IF;

END even;

FUNCTION odd (n NATURAL) RETURN BOOLEAN IS

BEGIN

IF n = 0 THEN

RETURN FALSE;

ELSE

RETURN even(n - 1); -- mutually recursive call

END IF;

END odd;

When the positive integer n is agreed to odd or even, the functions call each other by turns. At each call, the n is decremented. Eventually, n becomes zero and the final call returns TRUE or FALSE. For illustration, passing the number 4 to odd outcome in this series of calls:

odd(4)

even(3)

odd(2)

even(1)

odd(0) -- returns FALSE

On the other hand, passing the number 4 to even outcome in this series of calls:

even(4)

odd(3)

even(2)

odd(1)

even(0) -- returns TRUE


Related Discussions:- Mutual recursion

Create GUIs in PL/SQL, i NEED TO CREATE 3 guiS IN pl/sql sERVER PAGE FORM

i NEED TO CREATE 3 guiS IN pl/sql sERVER PAGE FORM

For-loop -iterative control, FOR-LOOP While the number of iterations thr...

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 ent

Using commit, Using COMMIT The COMMIT statements end the present trans...

Using COMMIT The COMMIT statements end the present transaction and make permanent any changes made during that transaction. Till you commit the changes, other users cannot acc

Block structure in pl/sql, Block Structure The PL/SQL is a block-struct...

Block Structure The PL/SQL is a block-structured language. That is, the fundamental units (procedures, anonymous blocks, and functions) that make up a PL/SQL program are logi

Constants and variables in pl sql, Constants and Variables:   You can...

Constants and Variables:   You can declare the constants and variables in the declarative section of any PL/SQL subprogram, block, or package. The Declarations allot the stor

Use triggers to maintain referential integrity, At times, Brewbean's has ch...

At times, Brewbean's has changed the id number for existing products. In the past, they have had to add a new product row with the new id to the BB_PRODUCT table, modify all the co

Predefined exceptions, Predefined Exceptions The internal exception is ...

Predefined Exceptions The internal exception is raised implicitly whenever your PL/SQL program exceeds a system-dependent limit or violates an Oracle rule. Each & every Oracle

Create a procedure to tax calculation task, Complete the following steps to...

Complete the following steps to create a procedure to calculate the tax on an order. The BB_TAX table contains the states that require taxes to be submitted for Internet sales. If

Overview of control structures-comparison operators, Overview of control st...

Overview of control structures According to the structure theorem, any computer program can be written by using the basic control structures as shown in figure below. They can b

Using limit - collection method, Using LIMIT For nested tables, that h...

Using LIMIT For nested tables, that have no maximum size, the LIMIT returns NULL. For varrays, the LIMIT returns the maximum number of elements that a varray can have (that yo

Write Your Message!

Captcha
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