Comparison of QBasic to Pascal

 

QBasic

Pascal

Variable

Do NOT need to be declared

eg. Name$

      Age

      Mark

Must declare at top of program with VAR

 VAR    name:STRING;

              Age:INTEGER;

              Mark:REAL;

Coments

REM  sample1

{ sample 1  }

 

Output to screen

PRINT      PRINT ; WRITELN(   )       WRITE(   )

PRINT hello there

WRITELN(hello there);

PRINT “1 st; first; “;2 nd; second

WRITELN(1 st ‘, first; ‘2 nd ’, second);

PRINT "hello" ;
PRINT "there"

WRITE('hello');
WRITELN('there');

 

Input from keyboard

INPUT

READLN(   );

 

INPUT “what is your name”, name$

 WRITE(‘what is your name’);
 READLN(name);

 

Assigning

total = a + b + c

total := a + b + c

 

IF

IF A >= 25 THEN

     calc = c * 5

     PRINT “the answer is”; calc

ELSE

     calc = c / 5

     PRINT “the result is”; calc

ENDIF

IF A >= 25  THEN
     BEGIN

      calc := c * 5;

      WRITELN(‘the answer is’, calc);

      END

ELSE

     BEGIN

     calc := c / 5;

     WRITELN(‘the result is “, calc);

     END;

Note: There is NEVER a semicolon
           BEFORE an ELSE

Loops

DO WHILE  num > 50

       .

       .

       .

LOOP

WHILE Num > 50 DO

      BEGIN

           .               ;

           .               ;

           .               ;

      END;

DO

      .

      .

       .

LOOP UNTIL   answer$ = “Y”

REPEAT

       .                  ;

       .                  ;

       .                  ; 

UNTIL answer = ‘Y’;

FOR j = 1 to 10 STEP 1

     .

     .

NEXT j

FOR J := 1 to 10 DO
     BEGIN

           .              ;

      END;