Qbasicnews.com
February 20, 2020, 12:11:48 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: recursive formula  (Read 1494 times)
banAnnA
Member
*
Posts: 56



« on: August 02, 2004, 09:13:50 AM »

I'd like to write a recursive formula to understand this principle better. I want the function to print something each time it passes. I tried to write such a thing before, but it only returns something (a number, eg.) and does not print while 'busy".

Can someone give me an example?
Logged
Sterling Christensen
Na_th_an
*****
Posts: 1328


« Reply #1 on: August 02, 2004, 09:34:14 AM »

Here's a very, very simple example. This will probably get up into the thousands before the program stops with an out of stack space error:
[syntax="qbasic"]DEFINT A-Z

DIM SHARED RecursionNumber

RecursionNumber = 0

DoIt

END

SUB DoIt

   RecursionNumber = RecursionNumber + 1

   PRINT "This is recursion #"; RecursionNumber

   DoIt

END SUB[/syntax]
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!