Qbasic Tutorial for beginners and children (Under Construction)

Enhancing Program Presentation

It's important for you to enhance you program by:

  • Documenting your program
  • Using meaningful variables
  • Saying what is the purpose of the program

Documenting your program

As you will notice later, programs may become huge, thus difficult to understand. The REM statement allows you to put remarks in your program. 

Any line starting with the REM statement is ignored at run-time.

You can replace the REM statement by a single-quote ( ' ) symbol.

The two lines below are similar:

REM Program written by H.B.
' Program written by H.B.

The single-quote form of REM can also be placed at the end of a line

PRINT "Welcome everybody" 'Welcome message

Using meaningful variables

The use single-letter variables may be easy to type especially if your typewriting speed is slow. However they may cause your program to be difficult to understand in the long-run. The use of meaningful variables makes your program easier to understand and maintain. 

Here is an illustration:

x = 2000

y = 10

z = x * (100 + y)/100

Could you guess the code above? Now see how it is easy when meaningful variables are used:

OldSalary = 2000

PercentageIncrease = 10

NewSalary  = OldSalary  * (100 + PercentageIncrease )/100

Saying what is the purpose of the program

Many novice programmers or children learning how to program, often neglect to say what is the purpose of their program. 

Example of an undocumented program:

a = 20

b = 30

c = a * b

PRINT "The product is "; c

As we said above, use the REM statement to put remarks, use meaningful variables and, at run-time, say what your program is doing.

REM This program calculates the product of 2 numbers: 20 and 30.
number1 = 20

number2 = 30

product = number1 * number2

PRINT "This program calculates the product of 2 numbers"

PRINT "The first number is"; number1

PRINT "The second number is"; number2

PRINT "The product is "; product


[ Previous Index Next ]

pages viewed since January  19 2002