An Introduction to Programming: Lesson 00

Computer programming is increasingly becoming an essential skill in many professions. Computers are one of the most powerful and useful tools available to us, and the ability to use them to solve problems is an important one when working in any of the STEM (Science / Technology / Engineering / Math) disciplines.

More importantly, though, programming can be fun!

Here’s a quick introduction, presented as a series of lessons that will get you started writing programs for your own computer. I’ve chosen to use FreeBASIC as the programming environment for several reasons, including ease of use, versatility, and low cost (meaning, no cost). While languages like C are more widely used in industry, FreeBASIC lends itself quite well to a “C-like” style of programming. Transitioning to C or another similar language would be mostly a matter of learning different syntax.

To write and run a program, you’ll need to:

  • Download and install FreeBASIC;
  • Start up FreeBASIC
  • Write a simple program or two (which I’ll provide, for now); and
  • Click a button to compile and run the program.

Downloading and installing FreeBASIC:

  • Click here to download a copy of the FreeBASIC installer.
  • Once it’s downloaded, run it and click through the prompts. (The default choices are fine.)
  • That’s it! On to the next step…

Starting up FreeBASIC:

  • Double-click on the FBIDE icon on your desktop.
  • (I told you it was easy.)

Writing your first program:

  • The traditional first program is a “Hello, World” program — one that simply prints “Hello, World.”
  • Click on the “New” icon at the upper right corner of the FreeBASIC program window (or click on File, then New.)
  • Type in the following:
    print “Hello, World!”
    sleep 5000
  • Click File -> Save, and give your program a name.
  • Press F9 to compile your program (translate it into something your computer can understand) and run it.
  • A new window with the phrase “Hello, World” should appear for five seconds, then disappear.
  • Congratulations — you just wrote a computer program!

Getting it to do more

  • The “Hello, World” program is nice and all, but it’s not really a fitting task for a computer capable of billions of calculations per second.
  • Why not have the computer add up all of the numbers between one and one million? (Don’t worry — it won’t take long.)
  • Click File -> Close, then File -> New. (Working with computer programs is really just like working with documents in Word and similar programs.)
  • Enter the following text in the window. (We’ll cover what this means in later lessons.)
    dim as ulongint x, total
    total = 0
    print “Adding the numbers…”
    for x=1 to 1000000
    total = total + x
    next x
    print “The total is: “;total
    sleep 10000
  • Click File -> Save, give the program a name (maybe “number sum” or something), then press F9.
  • You should quickly get the answer: 500000500000.

The next lesson will cover how to get started writing your own BASIC programs.

 

This entry was posted in Coding. Bookmark the permalink.

Leave a Reply