A nested loop is a loop within a loop, an inner loop within the body of an outer one. This repeats until the outer loop finishes. QBASIC allows to use one loop inside another loop. To understand nested loop following section shows a few examples.
Example 1
CLS
FOR i = 1 TO 4
PRINT "This is an outer loop "; i
FOR j = 1 TO 3
PRINT "Inner Loop "; j
NEXT j
PRINT
NEXT i
END
Example 2
CLS
FOR i = 1 TO 5
FOR j = 1 TO i
PRINT j;
NEXT j
PRINT
NEXT i
END
Example 3
CLS
FOR i = 1 TO 5
FOR j = 1 TO i
PRINT i;
NEXT j
PRINT
NEXT i
END
Example 4
CLS
FOR i = 5 TO 1 STEP -1
FOR j = 1 TO i
PRINT j;
NEXT j
PRINT
NEXT i
END
Example 5
CLS
FOR i = 5 TO 1 STEP -1
FOR j = 1 TO i
PRINT i;
NEXT j
PRINT
NEXT i
END