Indentation

From CometWiki

Revision as of 08:22, 31 May 2009 by Badge (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Indentation

Internet Basic statements may start at any position on the line. For more readable source code, you may indent instructions in order to highlight statement labels, illustrate loop constructs, show nested structures, etc. Example 1:

Before FOR HALFS=0 TO 2

  FOR QUARTERS=0 TO 4
  FOR DIMES=0 TO 10
  FOR NICKELS=0 TO 20
  FOR PENNIES=0 TO 100
  TOTAL=HALFS*50+QUARTERS*25+DIMES*10+NICKELS*5+PENNIES
  IF TOTAL = 100 THEN PRINT (0,1000)
  NEXT PENNIES
  NEXT NICKELS
  NEXT DIMES
  NEXT QUARTERS
  NEXT HALFS


After FOR HALFS=0 TO 2

    FOR QUARTERS=0 TO 4
      FOR DIMES=0 TO 10
        FOR NICKELS=0 TO 20
          FOR PENNIES=0 TO 100
            TOTAL=HALFS*50+QUARTERS*25+DIMES*10+NICKELS*5+PENNIES
            IF TOTAL = 100 THEN PRINT (0,1000)
          NEXT PENNIES
        NEXT NICKELS
      NEXT DIMES
    NEXT QUARTERS
  NEXT HALFS


Example 2:

Before PRINT (0) (ET)

  LABEL: PRINT (0) "WELCOME TO THE PROGRAM."
  PRINT (0) "WHAT IS YOUR NAME?"
  INPUT (0) NAME$
  .
  .
  GOTO LABEL


After PRINT (0) (ET)

  LABEL:   PRINT (0) "WELCOME TO THE PROGRAM."
           PRINT (0) "WHAT IS YOUR NAME?"
           INPUT (0) NAME$
           .
           .
           GOTO LABEL
Example 3: 

Before IF ENTERLEVEL = 0

  STOP
  ELSE
  EXIT
  ENDIF


After IF ENTERLEVEL = 0

     STOP
  ELSE
     EXIT
  ENDIF
Personal tools