Article by Ayman Alheraki on January 11 2026 10:32 AM
GW-BASIC Example from the 1980s
GW-BASIC was a simple programming language developed by Microsoft in the 1980s. It was widely used on IBM-compatible PCs and allowed users to write simple programs that could run directly from the MS-DOS environment. GW-BASIC is an interpreted language, meaning that each line of code is executed as it is read, which was particularly useful for beginners.
Here's a classic example of a GW-BASIC program from the 1980s that demonstrates some basic programming concepts like loops, conditionals, and input/output operations.
This program is a simple number-guessing game where the computer randomly picks a number between 1 and 100, and the player has to guess the number. The computer provides feedback whether the guessed number is too high or too low until the correct number is guessed.
xxxxxxxxxx10 PRINT "Welcome to the Number Guessing Game!"20 PRINT "I'm thinking of a number between 1 and 100."30 RANDOMIZE TIMER40 TARGET = INT(RND * 100) + 150 INPUT "Please enter your guess: "; GUESS60 IF GUESS < TARGET THEN PRINT "Too low! Try again."70 IF GUESS > TARGET THEN PRINT "Too high! Try again."80 IF GUESS = TARGET THEN PRINT "Congratulations! You guessed it!"90 IF GUESS <> TARGET THEN GOTO 50100 PRINT "Thanks for playing! Press any key to exit."110 ENDLines 10-20: These lines print introductory messages to the screen, welcoming the player to the game and explaining the rules.
Line 30: The RANDOMIZE TIMER statement initializes the random number generator using the system timer. This ensures that a different random number is generated each time the program runs.
Line 40: The program generates a random number between 1 and 100 using the RND function. The INT function converts the floating-point number produced by RND into an integer.
Line 50: The program prompts the player to enter a guess using the INPUT statement.
Lines 60-80: These lines contain conditional checks using IF statements to determine if the player's guess is too low, too high, or correct. If the guess is incorrect, the program provides feedback and asks for another guess.
Line 90: If the player's guess is incorrect, the program uses the GOTO statement to loop back to line 50 and prompt for another guess.
Line 100: Once the correct number is guessed, the program prints a closing message and ends with the END statement.
To run this program on a GW-BASIC interpreter (as was common in the 1980s):
Open GW-BASIC: Load the GW-BASIC interpreter on your MS-DOS machine or emulator.
Enter the Code: Type the lines of code exactly as written above.
Run the Program: Type RUN and press Enter.
This example highlights the simplicity and interactive nature of GW-BASIC, which made it an ideal language for beginner programmers in the 1980s. Programs like this number guessing game helped many aspiring developers learn the basics of programming logic, loops, conditionals, and user input/output operations.