Skip to content

Both.org

News, Opinion, Tutorials, and Community for Linux Users and SysAdmins

Primary Menu
  • About Us
  • Computers 101
    • Hardware 101
    • Operating Systems 101
  • End of 10 Events
    • Wake Forest, NC, — 2025-09-20
  • Linux
    • Why I use Linux
    • The real reason we use Linux
  • My Linux Books
    • systemd for Linux SysAdmins
    • Using and Administering Linux – Zero to SysAdmin: 2nd Edition
    • The Linux Philosophy for SysAdmins
    • Linux for Small Business Owners
    • Errata
      • Errata for The Linux Philosophy for SysAdmins
      • Errata for Using and Administering Linux — 1st Edition
      • Errata for Using and Administering Linux — 2nd Edition
  • Open Source Resources
    • What is Open Source?
    • What is Linux?
    • What is Open Source Software?
    • The Open Source Way
  • Write for us
    • Submission and Style guide
    • Advertising statement
  • Downloads
  • Home
  • Comparing BASIC with FORTRAN 77
  • Curiosity
  • History
  • Programming

Comparing BASIC with FORTRAN 77

I applied what I learned about BASIC to learn the FORTRAN 77 programming language.
Jim Hall May 25, 2024 8 minutes read
code_development_programming

If you grew up with computers like I did in the 1970s and 1980s, you probably learned a popular programming language for personal computers called BASIC, or the Beginner’s All-purpose Symbolic Instruction Code. You could find BASIC implementations on every personal computer of the era, including the TRS-80, Apple II, and the IBM PC. Back then, I learned AppleSoft BASIC on the Apple II before moving to GW-BASIC on the IBM PC and, later, to QuickBASIC on DOS.

But once upon a time, a popular language for scientific programming was FORTRAN, short for FORmula TRANslation. Although since the 1990 specification of the language, the name is more commonly stylized as “Fortran.”

When I studied physics as a university undergraduate student in the early 1990s, I used my experience in BASIC to learn FORTRAN 77. That was when I realized that BASIC derived many of its concepts from FORTRAN. To be clear, FORTRAN and BASIC differ in lots of other ways, but I found that knowing a little BASIC helped me to learn FORTRAN programming quickly.

I want to show some similarities between the two languages by writing the same program in both. I’ll explore the FOR loop in BASIC and FORTRAN 77 by writing a sample program to add a list of numbers from 1 to 10.

Bywater BASIC

BASIC came in many flavors, depending on your computer, but the overall language remained the same. One version of BASIC that I like is Bywater BASIC, an open source implementation of BASIC available for different platforms, including Linux and DOS.

To use Bywater BASIC on FreeDOS, you must first install the package from the FreeDOS 1.3 Bonus CD. To run it, go into the C: directory and type bwbasic. This command starts the BASIC interpreter. You can enter your program from this prompt:

bwBASIC:

Bywater BASIC uses an older BASIC programming standard that requires you to write every program instruction with a line number. Think of a line number like an index. You can easily refer to any instruction in the program with line numbers. As you type the program into the Bywater BASIC interpreter, add the line number before each instruction:

bwBASIC: 10 print "Add the numbers from 1 to 10 ..."
bwBASIC: 20 sum = 0
bwBASIC: 30 for i = 1 to 10
bwBASIC: 40 sum = sum + i
bwBASIC: 50 next i
bwBASIC: 60 print sum
bwBASIC: 70 end

Use the list command to view the program you have entered into the interpreter:

bwBASIC: list
10 print "Add the numbers from 1 to 10 ..."
20 sum = 0
30 for i = 1 to 10
40 sum = sum + i
50 next i
60 print sum
70 end

This short program demonstrates the FOR loop in BASIC. FOR is the most fundamental loop construct in any programming language, allowing you to iterate over a set of values. The general syntax of the FOR loop in Bywater BASIC looks like this:

FOR var = start TO end

In this example program, the instruction for i = 1 to 10 starts a loop that iterates through the values 1 to 10. At each pass through the loop, the variable i is set to the new value.

In BASIC, all instructions up to the next instruction are executed as part of the FOR loop. Because you can put one FOR loop inside another, Bywater BASIC uses the syntax NEXT variable to specify which loop variable to iterate.

Type run at the prompt to execute the program:

bwBASIC: run
Add the numbers from 1 to 10 ...
55

Bywater BASIC is called a BASIC interpreter because you can only run the program from inside the Bywater BASIC environment. This means the interpreter does all the hard work of interacting with the operating system, so your program doesn’t need to do that on its own, with the trade-off that the program runs a little slower in the interpreted environment than it might if it were a compiled program.

FreeBASIC

Another popular implementation of BASIC is FreeBASIC, an open source BASIC compiler for several platforms, including Linux and DOS. To use FreeBASIC on FreeDOS, you’ll need to install the FreeBASIC package from the FreeDOS 1.3 Bonus CD, then change into the C: directory where you’ll find the FreeBASIC programs.

FreeBASIC is a compiler, so you first create a source file with your program instructions, then run the compiler with the source code to create a program you can run. I wrote a similar version of the “add the numbers from 1 to 10” program as this BASIC file, which I saved as sum.bas:

dim sum as integer
dim i as integer
print "Add the numbers from 1 to 10 ..."
sum = 0
for i = 1 to 10
sum = sum + i
next
print sum
end

If you compare this code to the Bywater BASIC version of the program, you may notice that FreeBASIC doesn’t require line numbers. FreeBASIC implements a more modern version of BASIC that makes it easier to write programs without keeping track of line numbers.

Another key difference is that you must define or declare your variables in your source code. Use the DIM instruction to declare a variable in FreeBASIC, such as dim sum as integer, to define an integer variable called sum.

Now you can compile the BASIC program using fbc on the command line:

C:\DEVEL\FBC> fbc sum.bas

If your code doesn’t have any errors in it, the compiler generates a program that you can run. For example, my program is now called sum. Running my program adds up the numbers from 1 to 10:

C:\DEVEL\FBC> sum
Add the numbers from 1 to 10 ...
55

FORTRAN 77

The FORTRAN programming language is like a hybrid between old-style and modern BASIC. FORTRAN came before BASIC, and BASIC clearly took inspiration from FORTRAN, just as later versions of FORTRAN took cues from BASIC. You write FORTRAN programs as source code in a file but you don’t use line numbers everywhere. However, FORTRAN 77 does use line numbers (called labels) for certain instructions, including the FOR loop. Although in FORTRAN 77, the FOR is actually called a DO loop, it does the same thing and has almost the same usage.

In FORTRAN 77, the DO loop syntax looks like this:

      DO label var = start, end

This situation is one of the instances where you need a line number to indicate where the DO loop ends. We used a NEXT instruction in BASIC, but FORTRAN requires a line label instead. Typically, that line is a CONTINUE instruction.

Look at this sample FORTRAN program to see how to use DO to loop over a set of numbers. I saved this source file as sum.f:

      PROGRAM MAIN
      INTEGER SUM,I
      PRINT *, 'ADD THE NUMBERS FROM 1 TO 10 ...'
      SUM = 0
      DO 10 I = 1, 10
        SUM = SUM + I
   10 CONTINUE
      PRINT *, SUM
      END

In FORTRAN, every program needs to start with the PROGRAM instruction, with a name for the program. You might name this program SUM, but then you cannot use the variable SUM later in the program. When I learned FORTRAN, I borrowed from C programming and started all of my FORTRAN programs with PROGRAM MAIN, like the main() function in C programs, because I was unlikely to use a variable called MAIN.

The DO loop in FORTRAN is similar to the FOR loop in BASIC. It iterates over values from 1 to 10. The variable I gets the new value at each pass over the loop. This allows you to add each number from 1 to 10 and print the sum when you’re done.

You can find FORTRAN compilers for every platform, including Linux and DOS. FreeDOS 1.3 includes the OpenWatcom FORTRAN compiler on the Bonus CD. On Linux, you may need to install a package to install GNU Fortran support in the GNU Compiler Collection (GCC). On Fedora Linux, you use the following command to add GNU Fortran support:

$ sudo dnf install gcc-gfortran

Then you can compile sum.f and run the program with these commands:

$ gfortran -o sum sum.f
$ ./sum
ADD THE NUMBERS FROM 1 TO 10 ...
55

A few differences

I find that FORTRAN and BASIC are very similar, but with some differences. The core languages are different, but if you know a little of BASIC, you can learn FORTRAN. And if you know some FORTRAN, you can learn BASIC.

If you want to explore both of these languages, here are a few things to keep in mind:

FORTRAN 77 uses all uppercase, but later versions of FORTRAN allow mixed cases as long as you use the same capitalization for variables, functions, and subroutines. Most implementations of BASIC are case-insensitive, meaning you can freely mix uppercase and lowercase letters.

There are many different versions of BASIC, but they usually do the same thing. If you learn one BASIC implementation, you can easily learn how to use a different one. Watch for warnings or error messages from the BASIC interpreter or compiler, and explore the manual to find the differences.

Some BASIC implementations require line numbers, such as Bywater BASIC and GW-BASIC. More modern BASIC versions allow you to write programs without line numbers. FreeBASIC requires the -lang deprecated option to compile programs with line numbers.

This article is adapted from BASIC vs. FORTRAN 77: Comparing programming blasts from the past by Jim Hall, and is republished with the author’s permission.

Tags: basic fortran Programming

Post navigation

Previous: Get started with Midnight Commander, a visual shell and file manager for Linux
Next: Use ‘grep’ to solve a 2-dimensional word puzzle

Related Stories

command_line_prompt
  • Command Line
  • Linux
  • Programming

Writing a replacement seq command

Jim Hall April 27, 2026
learn-programming-code-keyboard
  • Linux
  • Programming

Writing a fun turn-based game

Jim Hall January 19, 2026
retro_old_unix_computer
  • FreeDOS
  • Fun
  • Programming

Old-school programming with BW BASIC

Jim Hall December 24, 2025

Random Quote

If a program is useless, it will have to be documented.

— Laws of Computer Programming

Why I’ve Never Used Windows

On February 12 I gave a presentation at the Triangle Linux Users Group (TriLUG) about why I use Linux and why I’ve never used Windows.

Here’s the link to the video: https://www.youtube.com/live/uCK_haOXPFM 

Why there’s no such thing as AI

Last October at All Things Open (ATO) I was interviewed by Jason Hibbits of We Love Open Source. It’s posted in the article “Why today’s AI isn’t intelligent (yet)“.

Technically We Write — Our Partner Site

Our partner site, Technically We Write, has published a number of articles from several contributors to Both.org. Check them out.

Technically We Write is a community of technical writers, technical editors, copyeditors, web content writers, and all other roles in technical communication.

Subscribe to Both.org

To comment on articles, you must have an account.

Send your desired user ID, first and last name, and an email address for login (this must be the same email address used to register) to subscribe@both.org with “Subscribe” as the subject line.

You’ll receive a confirmation of your subscription with your initial password as soon as we are able to process it.

Administration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

License and AI Statements

Both.org aims to publish everything under a Creative Commons Attribution ShareAlike license. Some items may be published under a different license. You are responsible to verify permissions before reusing content from this website.

The opinions expressed are those of the individual authors, not Both.org.

You may not use this content to train AI.

 

Advertising Statement

Both.org does not sell advertising on this website.


Advertising may keep most websites running—but at Both.org, we’re committed to keeping our corner of the web ad-free. Both.org does not sell advertising on the website. Nor do we offer sponsored articles at this time. We’ll update this page if our position on sponsorships changes.

We want to be open about how the website is funded. Both.org is supported entirely by David Both and a few other dedicated individuals.

 

 

Copyright © All rights reserved. | MoreNews by AF themes.