Database Reference
In-Depth Information
Then if you examine the code carefully, you see that there are two different types of
RETURN statements. First is the ordinary RETURN function in the following code snip-
pet:
IF (num <= 0)
THEN RETURN;
In this case it is used to terminate the function early if the length of desired sequence
of Fibonacci numbers is zero or less.
The second kind of RETURN statement is used to return values and continue execu-
tion:
RETURN NEXT a;
You may have noticed that there are a few other things we did differently in this
Fibonacci example than we did earlier. First, we declared and initialized the variables
a and b inside the DECLARE section, instead of first declaring and then initializing
them. We also used the argument as a down counter instead of using a separate
variable for counting from zero and then comparing it with the argument.
Both of these techniques save a few lines of code and may make the code more
readable depending on your preferences. But the longer versions might be easier to
follow and understand, so we don't particularly endorse either way.
Search WWH ::




Custom Search