Mutual recursion, PL-SQL Programming

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

Posted Date: 10/5/2012 5:47:53 AM | Location : United States







Related Discussions:- Mutual recursion, Assignment Help, Ask Question on Mutual recursion, Get Answer, Expert's Help, Mutual recursion Discussions

Write discussion on Mutual recursion
Your posts are moderated
Related Questions
Declaring Objects: You can use the object types wherever built-in types like CHAR or NUMBER can be used. In the block below, you can declare object r of type Rational. Then, yo

INSERT Statement The INSERT statement adds fresh rows of data to the specified database table or view. Syntax:

I want someone to write a TSQL function that returns the name of the ODBC DSN. I will use the queries below, to get information about the connection, but none of these return th

Parameter and Keyword Description: SQL: This SQL is the name of the implicit SQL cursor. %FOUND: This attribute results TRUE if an INSERT, DELETE, or UPDATE state

This is a Customer Management project. Customer data is presented in a text file. The program will load this text data into its DB columns. The data mapping is user definable. User

I would like to have a custom MS Access database designed and coded that would help me schedule my customer's orders and that would help me track my employees production output and

Seeking a programmer to design a legal document with pre-existing fields that could allow the auto-population of client(s) information (i.e. Name, Account Number, Address etc.) int

Map and Order Methods: The values of the scalar datatype like CHAR or REAL have a predefined order that allows them to be compared. While, the instances of an object type has

Deriving Predicates from Predicates in SQL The corresponding section in the theory book describes how predicates can be derived from predicates using (a) the logical connectiv

Components of an Object Type: An object type encapsulates the operations and data. Therefore, you can declare the methods and attributes in an object type specification, but no