Structured Programming in Basic Problems

© 1998 by Dr. Thomas W. MacFarland -- All Rights Reserved


     Instructions:   Review the following program and see if you can 
                     predict the outcome by completing a "pencil 
                     trace" of the code.  

                     Program output is provided at the end of this 
                     page.

     Compiler:       The program was prepared using GWBasic, which  
                     requires the use of line numbers.


10 REM This program demonstrates the use of LEN,
20 REM WHILE WEND, and Boolean logic with OR.
30 PUPPY$ = "" 'Set variable to null.
40 WHILE LEN(PUPPY$) < 5 OR LEN(PUPPY$) > 10
50   PRINT "Enter the name of your puppy at the ? prompt."
60   INPUT PUPPY$
70   PRINT PUPPY$
80 WEND
100 REM Enter Spot on the 1st iteration.
110 REM Enter King Rex the Wonder Dog on the 2nd iteration.
120 REM Enter Cherry on the 3rd iteration.
999 END
10000 REM And the answer is ...
10010 REM Enter the name of your puppy at the ? prompt.
10020 REM ? Spot
10030 REM Spot
10040 REM Enter the name of your puppy at the ? prompt.
10050 REM ? King Rex the Wonder Dog
10060 REM King Rex the Wonder Dog
10070 REM Enter the name of your puppy at the ? prompt.
10080 REM ? Cherry
10090 REM Cherry

Please send comments or suggestions to Dr. Thomas W. MacFarland

There have been [an error occurred while processing this directive] visitors to this page since February 1, 1999.