Archived: Recursion in LabVIEW 8.2 & 8.6This document has been archived and is no longer updated by National InstrumentsPrimary Software: LabVIEW Development Systems>>LabVIEW Base Development System Primary Software Version: 2017 Primary Software Fixed Version: N/A Secondary Software: N/A
Problem: How can I create recursive VIs in LabVIEW 8.2 & 8.6? Solution: To make a VI recursive in LabVIEW 8.2 and 8.6, follow the steps below. If you're running LabVIEW 2009 or later, refer to the White Paper: Creating Recursive VIs instead. About Recursion A VI that calls itself is referred to as a recursive VI. In other words, if a LabVIEW application uses recursion, it will open up additional copies of itself in order to complete some desired task. For example, one popular application of recursion is computing a factorial (denoted by the ! symbol). The factorial of any given positive integer is the product of all positive integers from one up to (and including) the given integer. So, 3! equals 3*2*1 = 6. The recursive factorial.vi example attached below computes a result by multiplying an integer by the next smallest integer's factorial (therefore calling itself). In mathematical terms, 3! = 3*(2!). Within this recursive factorial VI, 1! and 0! (a special case) are hardcoded to produce a result of 1. More information is located on the White Paper mentioned above. Reentrant VIs It is important to note that a recursive VI must open up additional copies of itself that each occupy their own space in memory. Equivalently, we can call such a VI reentrant. In other words, each instance of the recursive VI has its own data that is distinct from other instances of the VI. The steps listed below ensure that a recursive VI is configured for reentrant behavior. Steps to Create a Recursive VI Follow these instructions in order to program a VI that is capable of calling itself in LabVIEW 8.2 & 8.6:
Factorial Example Open the factorial.vi application attached below for an example of a recursive VI. Running the VI will produce the factorial of the input integer. Related Links: KnowledgeBase 2QKDG7DW: Differences Between Reentrant VIs, VI Templates, and Dynamic VIs White Paper: Creating Recursive VIs LabVIEW Help: Recursive VIs LabVIEW Help: Creating a Recursive VI Attachments:
Report Date: 02/15/2007 Last Updated: 09/12/2017 Document ID: 46EKS80E
