◄Example► ◄Contents► ◄Index► ◄Back► ────────────────────────────────────────────────────────────────────────────── ' This example uses a recursive FUNCTION procedure (a function that calls ' itself) to find and return the length of a string. ' To try this example: ' 1. Choose New Project from the File menu ' 2. Copy the code example below to the code window ' 3. Press F5 to run the example DECLARE FUNCTION StrgLng% (X$) CLS ' Clear the screen INPUT "Enter a string: "; InString$ PRINT "The string length is"; StrgLng%(InString$) FUNCTION StrgLng% (X$) IF X$ = "" THEN StrLng% = 0 ' The length of a null string is zero ELSE ' Non-null string; make a recursive call StrgLng% = 1 + StrgLng%(MID$(X$, 2)) ' The length of a non-null string is 1 plus ' the length of the rest of the string END IF END FUNCTION