Q Basic
Q Basic
7478085288
Lesson 1: QBASIC and the PRINT Statement (Very PRINT means show on the screen.
Easy)
Real-life example:
If you speak, people hear your words.
If the computer uses PRINT, we see words on the
1. Lesson Title screen.
Lesson 1: QBASIC and the PRINT Statement
4. Syntax
2. Learning Objectives This is the simple way to use PRINT:
After this lesson, you will be able to: PRINT "message"
• Tell what a program is Rules:
• Tell what QBASIC is • The word must be PRINT
• Use PRINT to show text on the screen • Text must be inside double quotes " "
• Run a simple QBASIC program • Each line runs from top to bottom
3. Concept Explanation (Very Simple Language + 5. Fully Commented Example Program (With Very
Real-Life Examples) Clear Meaning)
A computer is like a robot. REM Lesson 1 program
A robot needs instructions.
A computer also needs instructions. REM This program shows messages on the screen
QBASIC is a simple computer language. 7. Step-by-Step Explanation of the Code (Every Line
It is good for beginners. Clearly)
It is used in schools to learn programming.
Line 1:
What is PRINT?
REM Lesson 1 program
1
Abu Farhad Sardar
7478085288
• REM means “This is a note for humans.” PRINT "Hello"
• It helps us understand the program. Reason: Text must be inside " ".
Line 2: Wrong:
REM This program shows messages on the screen PRNT "Hello"
• This is also a note. Correct:
• It tells what the program does. PRINT "Hello"
• Again, the computer ignores this line. Reason: The computer needs the correct word.
Line 3:
Mistake 1: No quotes
10. Homework Challenge
Wrong: Homework
PRINT Hello Write a program to print this:
Correct:
2
Abu Farhad Sardar
7478085288
• Your name • A school bag stores books
Real-life example:
1. Lesson Title
Variable assignment
2. Learning Objectives A = 10
3. Concept Explanation (Very Simple Language + • Use $ for text (string) variables
Real-Life Examples) • Numbers do not use $
What is a Variable?
PRINT A 'Shows the number on the screen 10. Step-by-Step Explanation of Program 2
• INPUT NAME$
The computer asks for text.
6. Program Output (Program 1)
The user types a name.
If the user enters: The name is stored in NAME$.
• REM Program to input a number and print it Mistake 1: Forgetting $ for text
This is a comment.
Wrong:
It explains the program.
The computer ignores it. INPUT NAME
• INPUT A Correct:
The computer waits for the user.
The user types a number. INPUT NAME$
The number is stored in A. Mistake 2: Using quotes in INPUT
• PRINT A Wrong:
The computer shows the value stored in A.
INPUT "A"
Correct:
8. Fully Commented Example Program 2
INPUT A
Program 2: Input and print a name
Mistake 3: Mixing number and text variables
REM Program to input and print a name
Wrong:
A$ = 10
INPUT NAME$ 'Takes name from the user
A = 10
Homework
INPUT "A"
PRINT A
Program 3 (Wrong)
AGE$ = 12
PRINT AGE$
5
Abu Farhad Sardar
7478085288
Correct Program:
REM Program to input name Below is Lesson 3, created using the same lesson
template, written in very simple English, with real-life
INPUT NAME$
school examples.
PRINT "Hello "; NAME$ It is suitable for absolute beginners.
Problem:
INPUT should not have quotes.
1. Lesson Title
Correct Program:
Lesson 3: IF and IF…ELSE Statements
REM Program to input a number
INPUT A
2. Learning Objectives
PRINT A
After this lesson, you will be able to:
IF statement
IF…ELSE statement
6
Abu Farhad Sardar
7478085288
The IF…ELSE statement means: If the user enters:
“If this is true, do this.
5
Otherwise, do something else.”
Output:
Positive number
4. Syntax
(If the number is not positive, nothing is printed.)
IF statement
IF condition THEN
7. Step-by-Step Explanation of Program 1
statement
• INPUT A
END IF The computer asks for a number.
IF…ELSE statement The number is stored in A.
END IF • END IF
This ends the IF block.
Rules:
PRINT "PASS"
INPUT A 'Takes a number from the user
ELSE 'Runs when condition is false
PRINT "FAIL"
IF A > 0 THEN 'Checks if number is greater than 0
END IF 'Ends IF...ELSE
PRINT "Positive number"
7
Abu Farhad Sardar
7478085288
Output: Wrong:
PASS IF MARKS = 40 THEN
If the user enters: Better:
30 IF MARKS >= 40 THEN
Output:
Wrong:
10. Step-by-Step Explanation of Program 2 ELSE
• INPUT MARKS PRINT "FAIL"
The computer asks for marks.
• END IF
This ends the decision.
13. Homework Challenge
Homework
11. Common Mistakes
Write a program that:
Mistake 1: Forgetting END IF
• Inputs your age
Wrong:
• If age is 5 or more, print “School Student”
IF A > 0 THEN
• Else, print “Too young for school”
PRINT "Positive"
Bonus
Correct: Change the program to check:
IF A > 0 THEN • Primary student
PRINT "Positive" • Secondary student
END IF
8
Abu Farhad Sardar
7478085288
1. Lesson Title
2. Learning Objectives
• Understand repetition
9
Abu Farhad Sardar
7478085288
• Know why loops are used PRINT I 'Prints value of I
• Use the FOR…NEXT loop NEXT I 'Increases I and repeats the loop
• The loop stops at the end value FOR COUNT = 1 TO 3 'Loop will run 3 times
• NEXT tells the loop to move to the next value PRINT "Good Morning" 'Prints message
Good Morning
FOR I = 1 TO 5 'Loop starts with I = 1 and ends at 5 Good Morning
10
Abu Farhad Sardar
7478085288
FOR I = 5 TO 1
FOR I = 1 TO 5 Homework
PRINT I Bonus
NEXT J
Correct:
FOR I = 1 TO 5
PRINT I
NEXT I
Wrong:
11
Abu Farhad Sardar
7478085288
Below is Lesson 5, written using the same lesson
template, in very simple English, with clear daily-life
Simple comparison with FOR loop
examples, and a simple comparison with the FOR
loop. FOR Loop WHILE Loop
Lesson 5: WHILE…WEND Loop Starts and ends with Starts and ends with a
numbers condition
2. Learning Objectives
4. Syntax
After this lesson, you will be able to:
WHILE condition
• Understand conditional repetition
statement
• Use the WHILE…WEND loop
WEND
• Know when to use WHILE instead of FOR
Rules:
• Write simple WHILE loop programs
• Condition must be true to enter the loop
• Keep walking while the traffic light is red I=1 'Start value
In these cases:
• We do not know how many times the work WHILE I <= 5 'Loop runs while I is less than or
will repeat equal to 5
• We stop only when the condition changes PRINT I 'Prints the value of I
This is called conditional repetition. I=I+1 'Increases I by 1
What is WHILE…WEND? WEND 'Ends the WHILE loop
The WHILE…WEND loop means:
“Do this work while the condition is true.”
6. Program Output (Program 1)
12
Abu Farhad Sardar
7478085288
1 Good Evening
2 Good Evening
3 Good Evening
• COUNT = 1
The loop starts from 1.
7. Step-by-Step Explanation of Program 1
• WHILE COUNT <= 3
• I=1
The condition is checked.
The loop counter starts at 1.
• PRINT "Good Evening"
• WHILE I <= 5
The message is printed.
The computer checks the condition.
If true, it enters the loop. • COUNT = COUNT + 1
The count increases.
• PRINT I
The number is printed. • When COUNT becomes 4, the loop stops.
• I=I+1
The value of I increases.
11. Common Mistakes
This helps stop the loop later.
Mistake 1: Forgetting to change the value inside loop
• WEND
The loop goes back to check the condition Wrong:
again.
I=1
WHILE I <= 5
8. Fully Commented Example Program 2
PRINT I
Program 2: Print a message until count reaches 3
WEND
REM Program to print a message 3 times
Problem: Loop never stops.
Wrong:
WHILE COUNT <= 3 'Loop runs while count is 3
or less WHILE I <= 5
Wrong:
9. Program Output (Program 2) I = 10
13
Abu Farhad Sardar
7478085288
WHILE I < 5
PRINT I
WEND
Homework
• Starts from 1
• Prints numbers
Bonus
• FOR loop
Compare both programs.
14
Abu Farhad Sardar
7478085288
• Know when to use SELECT CASE instead of
IF…ELSE
Real-life examples:
o 1 for Tea
o 2 for Coffee
o 3 for Juice
• On a TV remote:
CASE value1
END SELECT
15
Abu Farhad Sardar
7478085288
Rules: Output:
• The computer checks the value of the variable You chose Coffee
Invalid choice
• INPUT CHOICE
User enters a number.
INPUT CHOICE 'Takes user choice
• SELECT CASE CHOICE
The computer checks the value.
SELECT CASE CHOICE 'Checks the value of • CASE 1
CHOICE Runs if choice is 1.
CASE 1 • CASE 2
PRINT "You chose Tea" Runs if choice is 2.
CASE 2 • CASE 3
Runs if choice is 3.
PRINT "You chose Coffee"
• CASE ELSE
CASE 3 Runs for any wrong number.
PRINT "You chose Juice" • END SELECT
CASE ELSE Ends the SELECT CASE block.
16
Abu Farhad Sardar
7478085288
INPUT D • CASE ELSE handles wrong input
END SELECT
12. Practice Exercises (Easy to Moderate)
3. English
10. Step-by-Step Explanation of Program 2
2. Menu for shapes:
• User enters a number
o
• SELECT CASE checks the number
1. Circle
• Matching CASE prints the day
17
Abu Farhad Sardar
7478085288
o
2. Square
3. Triangle
1. Addition
Lesson 7: Arrays (Single Dimensional)
•
2. Subtraction
1. Lesson Title
•
Lesson 7: Arrays (Single Dimensional)
3. Multiplication
Real-life examples:
A = 10
50
4. Syntax
Output:
Declaring an array
10
DIM A(5)
20
Using an array
30
A(1) = 10
40
Rules:
50
• DIM is used to create an array
19
Abu Farhad Sardar
7478085288
DIM A(5) 'Array to store numbers A(1) = 10
FOR I = 1 TO 5 Wrong:
INPUT A(I) 'Input numbers DIM A(5)
SUM = SUM + A(I) 'Add each number to SUM PRINT A(6)
NEXT I
INPUT A
9. Program Output (Program 2)
Homework
10. Step-by-Step Explanation of Program 2 Write a program that:
• DIM A(5) • Stores 10 numbers in an array
Creates array.
• Prints only even numbers
• SUM = 0
Starts total from zero. Bonus
Wrong:
20
Abu Farhad Sardar
7478085288
• You will build small but complete programs PRINT "Result = "; A * B
IF B <> 0 THEN
1 60
5 70
3 80
Output: 90
Result = 8 100
Output:
• Result is printed
SUM = 0
FOR I = 1 TO 5
NEXT I
• Division by zero
24
Abu Farhad Sardar
7478085288
Topic: Introduction to QBASIC & PRINT Statement
2. What is QBASIC?
1.
PRINT "Hello"
PRINT "QBASIC"
2.
Below are clean, printable practice worksheets for all 2. Write a program to print your school name.
8 QBASIC lessons, rewritten clearly and structured so
3. Print three different messages on the screen.
they can be directly printed or converted to PDF for
students.
Worksheet – Lesson 1
25
Abu Farhad Sardar
7478085288
B. Write the Output ELSE
1. PRINT "Small"
INPUT A END IF
(User enters: 8) 2.
2. INPUT M
2. Input two numbers and print their sum. 1. Check whether a number is positive or
negative.
3. Input your name and print a welcome
message. 2. Input marks and print PASS or FAIL.
Worksheet – Lesson 3
INPUT A 1.
26
Abu Farhad Sardar
7478085288
NEXT I WHILE X > 1
2. PRINT X
FOR I = 1 TO 3 X=X-1
NEXT I
1. Print numbers from 1 to 10. 2. Print your name 3 times using WHILE.
Worksheet – Lesson 6
4. One difference between FOR and WHILE. 5. Give one menu example from daily life.
1.
B. Write the Output
INPUT A
1.
SELECT CASE A
I=1
CASE 1
WHILE I <= 3
PRINT "One"
PRINT I
CASE 2
I=I+1
PRINT "Two"
WEND
CASE ELSE
2.
PRINT "Other"
X=4
END SELECT
27
Abu Farhad Sardar
7478085288
(User enters: 2)
3. What is an index?
SUM = 0
1. INPUT A
A(1)=5 NEXT I
A(3)=15 (Inputs: 2, 3, 5)
PRINT A(2) 2.
2. N=6
N(2)=6 ELSE
Just tell me
29