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
The Package Body The package specification is implemented by the package body. That is, the package body has the definition of every cursor and the subprogram declared in the p

Using Host Arrays The Client-side programs can use anonymous PL/SQL blocks to bulk-bind input and output host arrays. However, this is the well-organized way to pass the colle

Manipulating Local Collections Within PL/SQL, to manipulate the local collection, by using the  TABLE and CAST operators . The operands of CAST are a collection declared locally

Defining and Declaring Records To create records, you have to define a RECORD type, and then declare records of that type. You may also define RECORD types in the declarative

Use External Routines The PL/SQL is particular for the SQL transaction processing. Therefore, several tasks are more quickly completed in a lower-level language like C that is

Parameter Modes   To define the behavior of formal parameters you use the parameter modes. The 3 parameter modes, IN, OUT, & IN OUT, can be used with any subprogram. Though, a

Keys in SQL SQL support for keys in the following respects: SQL does not require at least one key for every base table. If no key is explicitly declared, then KEY {ALL B

Using the student and faculty tables create a select query that outputs all students for a specific advisor. Generate the execution plan, select out the explain plan . Create an

SQL Database: So, an SQL database is one whose symbols are organized into a collection of tables. Now, shows an SQL table as the current value of an SQL variable, ENROLMENT, b

Positional and Named Notation You can write the actual parameters when calling a subprogram, using either positional or named notation. That is, you can point to the relationsh