Main Differences of BASIC from FORTRAN

Program writing: Similar to FORTRAN, the BASIC program must also be written using a text file editor, such as Notepad or the MS-DOS Edit program. Every line must have a line number in BASIC, unlike FORTRAN where a line number is optional. Even the last END statement must have a line number. The allowed range of the line number is of course the same, that is, an integer from 1 to 99999 (i.e., 1- to 5- digit positive integer). Unlike FORTRAN, here the line number must continually increase from lines at the top to those at the bottom, though not necessarily in steps of one. The line number must obviously be followed by one or more space(s), followed by the content of the line -- in BASIC, this line content can be written beyond the line number and anywhere up to the 80th column and, so,  needn't be confined between 7th and 72nd column as in FORTRAN. Also, all variable names, keywords and commands must be written in uppercase, i.e., in capital letters, unlike in FORTRAN where uppercase is optional. An example of a BASIC program follows:

 5 REM Program to find the factorial of a natural number
10 INPUT "Enter the number to find factorial of: ", NUMBR%
11 LET PROD% = 1
12 FOR I% = 1 TO NUMBR%
13 LET PROD% = PROD%*I%
15 NEXT I%
16 PRINT "The factorial is:", PROD%
20 STOP
30 END

Let us now note that here in BASIC:

        1. A comment line starts with the REM keyword (it is the abbreviation of 'remark'), instead of with C or *.
        2. An input statement starts with the INPUT keyword (not READ, which has a different meaning). In the format-free way, there's no (*,*) here.
        3. An output statement starts with the PRINT keyword (not WRITE). To print the output, use LPRINT instead. In the format-free way, there's no (*,*) here.
        4. Unlike in FORTRAN, the symbols %  !  #  and  $  can be used in names of variables, but only as the ending character of the name, and that too, to mean definite types of variables. A variable name ending with  %  symbol means an integer numeric variable, with  !  symbol a single precision numeric variable, with  #  symbol a double precision numeric variable (one with more number of significant figures) and with  $  symbol a string (character) variable. If none of these four symbol is at the end of the variable name, then the variable is an ordinary numeric variable, or in other words a real (real numeric) one.
        5. Single apostrophe is not used here. Instead double apostrophe symbol ( " ) must be used to enclose any quoted part.
        6. The INPUT command has the characteristic form  [INPUT "Instruction for the user", V_Name]  -- because of which the necessity of a separate output statement (as in FORTRAN), instructing the user what to enter, doesn't arise here.
        7. Any assignment statement, assigning the value of a variable, must begin with the LET keyword. There's nothing similar to this in FORTRAN, but the meaning of the LET word in English is obviously relevant to the actual work that an assignment statement performs.
        8. A loop begins with a FOR statement and ends with a NEXT statement, instead of with DO and CONTINUE. The line number of the loop-ending line isn't written after the FOR statement. However, the looping variable (integer or even ordinary numeric - either of them are allowed here) follows similarly (above, it is I%). Next comes the equality ( = ) sign, and then comes the initial integer constant (say, 1) - or variable. Then comes the TO keyword (this is different from FORTRAN), followed by the final-value integer constant or variable (here NUMBR%). The increment is not stated in BASIC, but it is always 1.
        9. The loop ends with a line starting with the NEXT keyword followed by a space and then the looping variable name (here I%).
      10. The program ends with STOP and END as in FORTRAN, but here both these lines must also be numbered. The line number of the END statement line is naturally the largest line number of the program.

Program Execution: The BASIC program must be saved as a text file having the .bas  extension, instead of the .for  extension for FORTRAN programs (take care so that the default .txt  extension does not arise). Unlike FORTRAN, there is no facility to check the written BASIC program, nor any need to create an object or an executable program i.e., nothing similar to the FTN77, FCG77 or LINK86/F commands. The written, unchecked program can be directly loaded and run within the BASIC package window, which is obtainable by opening (say, by double-clicking) the BASIC executable package. However, before running the written program, it must be loaded by entering a command such as LOAD "1st_Name.bas" or LOAD "1st_Name" within the BASIC package window. While one written program remains loaded, that may be run by entering the RUN command within the package window. To exit from the BASIC package window, one has to enter the command SYSTEM.

Conditional Statements: In BASIC, the conditional statement involves IF, THEN and ELSE keywords similar to FORTRAN, but the whole conditional structure must occur within one line only, and there is no ENDIF keyword to mark the end of the conditional structure. Instead of the THEN keyword, the GOTO keyword may also be placed but that must be followed by a line number to go to. Also, THEN and ELSE keywords may each be followed by simply a line number (e.g., 65) instead of a proper statement (e.g., the statement PRINT "The roots are complex!"), to shift execution of the program to those line numbers. The line number(s) thus referred are generally later ones. Also note that the ELSE part is optional, i.e., it may or may not be present. Thus, the two possible syntax for the conditional statement are as follows:
        IF [condition][,] THEN statement/line-number [[,] ELSE statement/line-number] 
        IF [condition][,] GOTO line-number [[,] ELSE statement/line-number]
Note that the condition and the THEN (or GOTO) parts need be separated by a comma, unlike in FORTRAN. Similarly, before the ELSE part, if present, there need be a comma. Unlike in FORTRAN, the condition isn't generally enclosed in brackets.

The conditional operators comparing, generally, a constant and a variable (or two constants or two variables) are different in BASIC. They look simpler here:
        >   implying greater than
        <   implying less than
        =   implying equal to
        <>  implying not equal to
        >=  implying greater than or equal to
        <=  implying greater than or equal to
On both sides of such an operator lies the constants or variables to be compared, thus forming the [condition] mentioned above.

The following are two examples of BASIC programs that find the real roots, if any, of a quadratic equation Ax2 + Bx + C = 0, by utilizing conditional statements.

1 PRINT "Program to find the real roots of a quadratic equation"
2 PRINT " "
11 INPUT "Enter value of the coefficient A: ", A
12 INPUT "Enter value of the coefficient B: ", B
13 INPUT "Enter value of the coefficient C: ", C
20 LET B2M4AC = B^2 - 4*A*C
30 IF B2M4AC < 0.0, THEN 40, ELSE LET DENOM = 2*A
31 LET R1 = (-B + SQR(B2M4AC))/DENOM
32 LET R2 = (-B - SQR(B2M4AC))/DENOM
33 PRINT "The real roots are: ", R1, "and", R2
34 GOTO 50
40 PRINT "The roots are complex"
50 STOP
51 END


1 PRINT "Program to find the real roots of a quadratic equation"
2 PRINT " "
11 INPUT "Enter value of the coefficient A: ", A
12 INPUT "Enter value of the coefficient B: ", B
13 INPUT "Enter value of the coefficient C: ", C
20 LET B2M4AC = B^2 - 4*A*C
30 IF B2M4AC >= 0.0, GOTO 31, ELSE 40
31 LET R1 = (-B + SQR(B2M4AC))/(2*A)
32 LET R2 = (-B - SQR(B2M4AC))/(2*A)
33 PRINT "The real roots are: ", R1, "and", R2
34 GOTO 50
40 PRINT "The roots are complex"
50 STOP
51 END

N.B.: Note the SQR operator (instead of SQRT) in BASIC and the sign ^ (instead of **) used as its exponentiation operator.