In QB.EXE, Improper FOR NEXT Control after NEXT Is Inserted (35666)






This article was previously published under Q35666

SYMPTOMS

In the QB.EXE editor, when a NEXT statement is inserted inside a nested FOR NEXT loop after a "FOR WITHOUT NEXT" error has occurred, loop control is incorrectly executed.

STATUS

Microsoft has confirmed this to be a bug in Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, and in the QB.EXE that comes with the Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2 (buglist6.00, buglist6.00b). This problem was corrected in the Microsoft Basic PDS Version 7.00 (fixlist7.00).

MORE INFORMATION

To duplicate this problem, do the following:

  1. Enter the following code in the QuickBasic editor:
          CLS
          FOR k = 1 to 5
            FOR l = 1 to 2
              PRINT k
    
          NEXT
    						
    Running this will give the FOR WITHOUT NEXT error.
  2. Insert another NEXT statement after the "PRINT k" and run the program again.

    The output should be as follows:
          1   1   2   2   3   3   4   4   5   5
    						
    However, it is as follows:
          1   1   2   2
    						
    If the NEXT is inserted after the already existing NEXT, the program runs correctly.

Modification Type: Minor Last Reviewed: 1/9/2003
Keywords: KB35666