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

Assignment of variable - updating a variable, Assignment of Variable - Upda...

Assignment of Variable - Updating a Variable Syntax: SET SN = SID ('S2'); This can obviously be read as "set the variable SN to be equal in value to SID ( 'S2' )".

Boolean values-assignments in pl/sql, Boolean Values Only the values TRU...

Boolean Values Only the values TRUE, FALSE, & NULL can be assigned to a Boolean variable. For illustration, given the declaration DECLARE done BOOLEAN; the following statements

Package standard, Package STANDARD The package named STANDARD defines t...

Package STANDARD The package named STANDARD defines the PL/SQL atmosphere. The package specification globally declares the exceptions, types, and subprograms that are available

Functions in pl/sql, Functions   The function is a subprogram that cal...

Functions   The function is a subprogram that calculates a value. The Functions and procedures are structured similar, except that the functions have a RETURN clause. You can

Cursor attributes in pl sql, Cursor Attributes   The Cursors and curso...

Cursor Attributes   The Cursors and cursor variables have 4 attributes which give you helpful information about the execution of a data manipulation statement. Syntax:

Seeking a programmer to design a legal document, Seeking a programmer to de...

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

Using a host variable, Using a Host Variable You can declare the curso...

Using a Host Variable You can declare the cursor variable in the PL/SQL host environment like an OCI or Pro C program. To use the cursor variable, you should pass it as a host

Overloading method in pl/sql, Overloading: Similar to packaged subprog...

Overloading: Similar to packaged subprograms, methods of the same type can be overloaded. That is, you can use similar name for various methods if their formal parameters diff

Parameter and keyword description - %type attribute, Parameter and Keyword ...

Parameter and Keyword Description: collection_name: This keyword identifies the index-by table, nested table, or varray formerly declared within the present scope. cu

Declaring exceptions - user-defined exceptions, Declaring Exceptions T...

Declaring Exceptions The Exceptions can be declared only in the declarative part of the PL/SQL subprogram, block, or package. By introducing its name, you can declare an excep

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