ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
FOR...NEXT Statement Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example uses FOR...NEXT loops to print the first 11 columns of
' Pascal's Triangle, in which each number is the sum of the number
' immediately above it and the number immediately below it in the preceding
' column.
 
' 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
 
 DEFINT A-Z
 CLS                                   ' Clear the screen
 CONST MAXCOL = 11
 DIM A(MAXCOL, MAXCOL)
 PRINT "Pascal's Triangle"
 FOR M = 1 TO MAXCOL
     A(M, 1) = 1: A(M, M) = 1          ' Top and bottom of each column is 1
 NEXT M
 FOR M = 3 TO MAXCOL
     FOR N = 2 TO M - 1
          A(M, N) = A(M - 1, N - 1) + A(M - 1, N)
     NEXT N
 NEXT M
 Startrow = 13                         ' Go to the middle of the screen
 FOR M = 1 TO MAXCOL
     Col = 6 * M
     Row = StartRow
     FOR N = 1 TO M
          LOCATE Row, Col: PRINT A(M, N)
     Row = Row + 2                     ' Go down 2 rows to print next number
     NEXT N
     PRINT
     StartRow = StartRow - 1           ' Next column starts 1 row above
 NEXT M                                ' preceding column