QBasic Programming Tutorial
Step-by-step guide for beginners
1. Data Types
• Integer - Whole numbers (e.g., 10, -5)
• Single - Decimal numbers (e.g., 3.14)
• String - Text (e.g., "Hello")
• Example:
• DIM age AS INTEGER
• DIM salary AS SINGLE
• DIM name AS STRING
2. Constants and Variables
• Constants: Fixed values
• Variables: Used to store data
• Example:
• CONST PI = 3.14
• DIM radius AS SINGLE
• radius = 5
3. Expressions and Assignments
• Use expressions to calculate values
• Assignment uses '='
• Example:
• a = 10
• b = 20
• sum = a + b
4. Operators and Precedence
• Operators: +, -, *, /, ^
• Precedence follows BODMAS
• Examples:
• result = 2 + 3 * 4 'Output: 14
• result = (2 + 3) * 4 'Output: 20
5. Input/Output Statements
• INPUT - Take user input
• PRINT - Display output
• Example:
• INPUT "Enter name: ", name$
• PRINT "Hello, "; name$
6. Built-in Functions
• ABS(x) - Absolute value
• SQR(x) - Square root
• INT(x) - Integer part
• LEN(s) - String length
• UCASE$, LCASE$ - Case conversion
7. Sequential and Conditional
Execution
• Sequential: Line by line execution
• Conditional: Executes based on condition
• Example:
• IF age >= 18 THEN
• PRINT "Adult"
• ELSE
• PRINT "Minor"
• END IF
8. Looping Constructs
• FOR loop: FOR i = 1 TO 5 ... NEXT i
• WHILE loop: WHILE i <= 5 ... WEND
• DO UNTIL loop: DO UNTIL i > 5 ... LOOP
9. Single Dimensional Arrays
• Stores multiple values
• Example:
• DIM marks(5) AS INTEGER
• FOR i = 1 TO 5: INPUT marks(i): NEXT i
• FOR i = 1 TO 5: PRINT marks(i): NEXT i
10. Nested Loops
• Loop inside another loop
• Example:
• FOR i = 1 TO 3
• FOR j = 1 TO 2
• PRINT "i = "; i; " j = "; j
• NEXT j
• NEXT i