QBASIC Commands

Codynn
4 Min Read

Introduction:

During the 1980s and 1990s, Microsoft’s QBASIC programming language played a crucial role in introducing newcomers to the coding realm. Even though newer languages have gained popularity, familiarizing yourself with QBASIC commands can establish a strong basis in programming principles. In this blog, we’ll explore different QBASIC commands using simple code illustrations, enabling you to easily grasp the core concepts of this timeless language.

1. PRINT Command:

The PRINT command is essential for displaying output in QBASIC. It allows you to show text and variables on the screen.

CLS
PRINT "Hello, QBASIC!"

2. INPUT Command:

The INPUT command enables user interaction by accepting input from the keyboard. It’s a fundamental part of creating interactive programs.

CLS
INPUT "What's your name: ", name$
PRINT "Hello, "; name$; "!"

3. LET Command:

Although not always necessary, the LET command assigns a value to a variable. In modern languages, this step is implicit.

LET x = 10
LET y = 5
PRINT x + y

4. IF…THEN…ELSE Statement:

Conditional logic is crucial in programming. The IF...THEN...ELSE statement allows you to execute different code blocks based on conditions.

CLS
INPUT "Enter your age: ", age
IF age >= 18 THEN
    PRINT "You are an adult."
ELSE
    PRINT "You are a minor."
END IF

5. FOR…NEXT Loop:

Loops are used for repetitive tasks. The FOR...NEXT loop helps you iterate through a sequence of numbers.

CLS
FOR i = 1 TO 5
    PRINT "Current value of i: "; i
NEXT

6. DO…LOOP Statement:

The DO...LOOP statement allows you to create loops with conditions checked at the beginning or end of the loop.

CLS
count = 1
DO
    PRINT "Count: "; count
    count = count + 1
LOOP WHILE count <= 5

7. GOTO Statement:

The GOTO statement transfers control to a specific line number in your program. While it can make code hard to follow, it’s a classic feature of QBASIC.

CLS
PRINT "Welcome to QBASIC!"
GOTO 10
PRINT "This won't be displayed."
10 PRINT "You've reached line 10!"

8. SUB and FUNCTION Procedures:

Procedures allow you to group code for better organization. SUB procedures don’t return a value, while FUNCTION procedures do.

CLS
SUB DisplayMessage(message$)
    PRINT message$
END SUB

FUNCTION AddNumbers(a, b)
    AddNumbers = a + b
END FUNCTION

CALL DisplayMessage("Hello from a SUB procedure!")
result = AddNumbers(3, 5)
PRINT "Result: "; result

9. END Statement:

The END statement indicates the end of your program. Any code after END won’t be executed.

CLS
PRINT "This is the beginning."
END
PRINT "This won't be displayed."

Conclusion:

Even though QBASIC is an old programming language, it’s a great choice for beginners. Learning its basic commands can help you understand programming concepts used in many different languages. While newer languages have fancier features, QBASIC is still useful for learning because it’s simple and has a cool history.

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *