SlideShare uma empresa Scribd logo
1 de 30
Submitted by:
Jovelle D. Luzon
Dianne Myrell V. Sandoval
Submitted to:
Mr. Angel Corona
BASIC stands for Beginner’s All Purpose Symbolic
Introduction Code. It was invented in 1963, at Dartmouth
Collage, by the mathematicians John George Kemeny and
Tom Kurtzas.
BASIC is an interpreter which means it reads every line,
translates it and lets the computer execute it before
reading another. Each instruction starts with a line
number.
INTRODUCTION TO
QBASIC
FEATURES OF QBASIC
 It is a user friendly
language.
 It is widely known and
accepted programming
language.
 It is one of the most flexible
languages, as modification
can easily be done in already
existing program
 Language is easy since the
variable can be named easily
and uses simple English
phrases with mathematical
expressions.
RULES OF QBASIC
Every programming language has a set of
rules that have to be followed while
writing a program, following are some
rules of QBASIC language:
 All QBasic programs are made up of
series of statements, which are
executed in the order in which they
are written.
 Every statement should have at least
one QBasic command word. The
words that BASIC recognizes are
called keywords.
 All the command words have to be
written using some standard rules,
which are called “Syntax Rules”.
Syntax is the grammar of writing the
statement in a language. Syntax Errors
are generated when improper syntax
is detected.
QBASIC DATA
Data is a collection of facts and figures that is entered into the computer
through the keyboard. Data is of two types:
CONSTANT: Data whose value does
not change or remains fixed. There
are two types of constants:
 (a) NUMERIC
CONSTANT: Numbers –
negative or positive used
for mathematical
calculations.
e.g. -10, 20, 0
(b) ALPHANUMERIC
CONSTANT/STRING:
Numbers or alphabets
written within double
quotes(inverted commas “
“).
e.g. “Computer”,
“Operating System”
VARIABLE: Data whose value is not
constant and may change due to some
calculation during the program execution.
There are two types of variables.
 (a) NUMERIC VARIABLE: The
value that holds a Numeric
Constant for arithmetic
calculations (+, -, *, /) is called a
Numeric Variable.
e.g. A = 50, here A is the Numeric
Variable
(b) ALPHANUMERIC VARIABLE:
Cannot be used for arithmetic
calculations. Alphanumeric
Number must end with a $ sign
and must be enclosed in inverted
commas.
e.g. Name$ = “Akanksha”,
here Name$ is an Alphanumeric
Variable.
Once QBASIC PROGRAM is loaded into the computer memory, it displays Ok
prompt. Ok means it already to accept the commands. QBASIC can be made to
translate your instructions in two modes:
Direct Mode
Program Mode
1. Direct Mode: The accepts single line instructions from the user and the output
is viewed as soon as enter key is pressed. The instructions are not stored in the
memory. This mode can be used to do quick calculation. They do not have
lines. E.g.
Print 3+4
Print “This is the Direct mode in QBasic”
2. Program Mode: The mode is used to type a program which is stored in the
memory. They have line numbers. We have to give the command to get the output.
e.g.
10 Print 3+4
20 End
RUN
Programs are built up with set of instructions or commands. Every programming
language has its own SYNTAX (rules) and COMMANDS.
TYPES OF MODE IN
QBASIC
The following commands do not need line number.
LIST- the command is used to list the program on the screen.
RUN- the command is used to execute the program.
LLIST- the command is used to list of program as a hardcopy.
LPRINT- the command is used to get the output of the program on
the hardcopy.
NEW- the command is used clear the memory of the existing
program.
SYSTEM- the command is used to take you back to dos prompt.
PRINT AND CLS- the command cam also be used without a
line number. Print is used to view the display on the screen and
CLS to clear the screen.
RME- the command is used to show the position of the mistake.
SAVE- the keyword is used to save the program.
LOAD- the keyword is used to LOAD the program from the disk to
the memory.
COMMAND/KEYWORDS IN QBASIC
AND THEIR FUNCTIONS
1. CLS: This command is used to clear the screen.
2. PRINT: Print command is used to display the output on the
screen.
E.g. Print “HELLO WORLD!!!”
Print 80 * 8
Print Tab(10) “Navrachana”- will print Navrachana on 10
column.
3.REM: Stands for Remark. It gives an explanation of the program or
of the statements in the program more understandable to the reader.
4. LET: It assigns a value to a variable in a program. It stores value in
the memory location.
QBASIC COMMANDS
 SYNTAX: Let <Variable>=<Constant/Variable or
Expression>
e.g. Let A = 15……..Assigning constant to a variable
Let A = B……..Assigning variable to a variable
LET C = A+B….Assigning an expression to a
variable
Using Let with Numeric Variables: Let A = 50,
here A is a Numeric Variable and ‘50’ is a Numeric
Constant and the value ‘50’ is assigned to a and stored
in the computer’s memory for further calculations.
Using Let with Alphanumeric Variable: Let N$
= “QBasic Program”, here N$ is an Alphanumeric
Variable and “QBasic Program” is the Alphanumeric
Constant assigned to N$.
Note: A numeric data should be assigned to a
Numeric variable and an alphanumeric data to an
alphanumeric variable otherwise “TYPE
MISMATCH” error is displayed.
5. END- This command is usually given at the
end of the program.
6.INPUT: This statement allows the user to
enter a value for the variable while running the
program.
SYNTAX: INPUT <VARIABLE>
e.g. Input A…..Enter Numeric constant
Input N$.....Enter Alphanumeric constant
Input “Enter name:”;N$.....Giving
relevant message to avoid erroneous data input
7. DELETE <LINE NO.>: To delete a line
number in a program. e.g.
Delete 10 will delete line number 10
Delete 30-50 will delete all the line between 30 to 50.
Print with Comma (,): The screen of the computer is
made of 80 columns and 40 rows. The columns are
divided into five (5) zones 14 columns each. Comma
placed after the message prints the message zone wise
on the screen.
Print with Semi-Colon (;) Semi-Colon placed after the
message to be displayed, leaves no space between two
messages.
e.g. Print “This is an example”;” of QBasic program”
Output: This is an example of QBasic program
QBASIC REMINDER
A QBASIC program consists of lines containing
1. A line number
2. A QBASIC keyword like PRINT ,END etc
3. Each program line begins with positive number.
4. No two lines should ha same number.
RUNNING A PROGRAM
RUN is the command used to execute the program and get
the output on the screen.
WRTING A NEW PROGRAM
It is possible to overwrite lines with a new statements, but if
you want to write a totally new program use a NEW
command.
EXITING QBASIC
In order to exit the QBASIC program SYSTEM command is
used.
There are also special functions called “commands” (also called “instructor”). A
“command” tells the QBasic interpreter to do something.
The PRINT command tells the QBasic interpreter to print something to the screen. In this
case, the interpreter printed “Hello World!”.
With the PRINT command, you can also print numbers to the screen. Delete the current
program (unless you already have) and write the following:
PRINT 512 (or ?512)
<press Enter>
Press F5 to run the program. The program outputs:
512
COMMANDS
TIPS: Instead of typing
PRINT, you can enter a
question mark. For example:
?”Hello World!”
An expression is something the interpreter calculates
(evaluates). Such as:
1 + 1 ( returns 2)
100 – 47 ( returns 53)
3 + 34 ( returns 102 )
80 / 4 ( returns 20 )
( 100 * 3 ) + 56 ( returns 356 )
EXPRESSIONS
NOTE: The asterisk ( * )
means to multiply two
numbers; the slash ( / )
means to divide

If you pass an expression to the PRINT command, the value
returned (a number) is printed.
Clear the current program, and then run the following:
PRINT 512 + 478
Program output:
990
IF you enclose the expression with quotation marks, the expression
becomes a string and isn’t evaluated. For example:
PRINT “512 + 478”
Output:
512 + 478
TIP: To clear the output screen, use
the CLS command.
You can use multiple print statements in your program.
PRINT “Hello”
PRINT “World”
Output:
Hello
World
To place World onto the previous line, place a semi-colon after PRINT “Hello”.
PRINT “Hello”;
PRINT “World”
Output:
HelloWorld
Also, if you put a comma instead of a semi-colon on the first line, the program will insert
spaces between the two words.
PRINT “Hello”,
PRINT “World”
Output:
Hello World
More about the PRINT
command
This chapter discusses an important topic in programming, “variables.”
Please read this section thoroughly.
A variable is a piece of data kept in the computer’s memory (RAM). The
location of a variable in RAM is called the “address.”
Variables
Memory address Value
999997 0
999998 0
999999 0
1000000 0
1000001 0
1000002 0
1000003 0
Variable

How a variable is stored in RAM
The following program prints the variable x to the screen.
print x
Since the variable hasn’t been assigned a number, the
value of the variable is 0. So, the output of the program
is:
0
The next program sets x to15, and then prints the
variable:
x = 15
print x
The time, the output is:
15

In the above example, the number 15 was stored in the
computer’s RAM at a certain memory address. Then the
PRINT command accessed (or looked at) that address
when it printed “15” to the screen.
Memory address Value
999997 0
999998 0
999999 0
1000000 0
1000001 0
1000002 0
1000003 0
Variable X

(NOTE: The memory address of x is not necessarily 1000000)
As in the program above, a variable is accesses by calling its name. Variable
names can have a combination of letters and numbers. The following are valid
variables:
Y
num
VALUE
xYz
abc123
ADVANCED TIP: Although you don’t
normally need to, you can find the actual
memory address of a variable (x, for example)
by using the VARSEG and VARPTR
commands.
PRINT (VARSEG(X) * VARPTR(X)
One way to receive input from the keyboard is with the INPUT
command. The INPUT command allows the user to enter either a string
or a number, which is then stored in a variable.
INPUT data$
PRINT data$
When this program is executed, the INPUT command displays a
question mark, followed by a blinking cursor. And when you enter text,
the program stores that text into the variable data$, which is printed to
the screen.
Retrieving Keybord input
from the user
TIP: If you place a string and a semi-colon
between INPUT and the variable, the
program will print the string.
INPUT “Enter some text:”; data$
To receive a number, use non-string variable.
INPUT number
PRINT number
If you enter text instead of a number, the Qbasic interpreter displays an error
message ( “Redo from start “ ).
Below is another example of the INPUT command:
PRINT “ Enter some text : “
INPUT text$
PRINT “ Now enter a number : “
INPUT num
PRINT text$
PRINT num
TIP: you can have the question
mark displayed on the previous
line by using a semi-colon.
PRINT “ Enter some text:”;
INPUT text$
The IF and THEN commands are used to compare an
expression and then perform some task based on that
expression.
x = 5
IF x = 5 THEN PRINT “ equals 5 “
Since x does equal 5 in this case, the program outputs:
x equals 5
The IF and THEN
commands
You can also enter the following statements, instead of the
equals sign:
x < 5 (x is less than 5)
x > 5 (x is greater than 5)
Run the following:
x = 16
IF (x > 5) THEN PRINT “x is greater than 5”
Ouput:
x is greater than 5
Expression signs
You can also combine the signs like this:
x <= 5 (x is less than or equal to 5)
x >= 5 (x is greater than or equal to 5)
x <> 5 (x does not equal 5)
Run the following example:
CLS
x = 5
IF (x >= 5) THEN PRINT “x is greater than or equal
to 5”
IF (x <= 5) THEN PRINT “x is less than or equal to 5”
IF (x <> 5) THEN PRINT “x does not equal to 5”
Output:
x is greater than or equal to 5
x is less than or equal to 5

 Using the ELSE command, you can have the
program perform a different action if the statement is
false.
x = 3
IF x = 5 THEN PRINT “Yes” ELSE PRINT
“No”
Since x doesn’t equal 5, the output is:
No
ELSE
 END IF allows you to have multiple commands after the IF. . .THEN statement, but
they must start on the line after the IF statement. END IF should appear right after the
list of commands.
x = 5
IF (x = 5) THEN
INPUT a$
PRINT a$
END IF
The following program uses ELSE with the END IF command:
x = 16
IF (x = 5) THEN
INPUT a$
PRINT a$
ELSE
PRINT x * 2
END IF
Output:
32
END IF
TIP: There is a way to have
multiple commands after IF. .
.THEN without using END IF. To
do so, place a colon between each
command.
IF (x = 5) THEN PRINT a$: PRINT
a$
The ELSEIF command allows you to perform a secondary action if the first expression was false. Unlike ELSE,
this task is only performed if specified statement is true.
x = 6
IF ( x = 6 ) THEN
PRINT “ Statement 1 is true “
ELSEIF ( x = 6 ) THEN
PRINT “ Statement 2 is true “
ENDIF
Output:
Statement 2 is true
You can have multiple ELSEIF commands, along with ELSE.
x = 8
IF (x = 5) THEN
PRINT “Statement 1 is true”
ELSEIF (x = 6) THEN
PRINT “Statement 2 is true”
ELSEIF (x = 7) THEN
PRINT “Statement 3 is true”
ELSE
PRINT “No above statement are true”
END IF
Output:
No above statements are true
ELSEIF
You can have more than one expression in IF. . .THEN by using either the OR operator or the
AND operator.
The OR operator only requires one expression to be true in order to print “Yes” in the following
program:
x = 20
IF (x = 5 OR x = 20) THEN PRINT “Yes”
Output:
Yes
The AND operator requires both expressions to be true.
x = 7
IF (x > 5 AND x < 10) THEN PRINT “True”
Output:
True
This is a slightly more complex examples:
x = 16
y = 3
IF ((x > 5 AND x < 10) OR y = 3) THEN PRINT “Correct”
Output (since Y is 3):
Correct
Multiple expressions

So far this chapter, we’ve only been dealing with
numbers, but you can also use strings with the IF. .
.THEN command.
x$ = “Hello”
IF (x$ = “Hello” OR x$ = “World”) THEN PRINT x$
Output:
Hello
Strings in IF. . .THEN

Jovelle D. Luzon
Dianne Sandoval

Mais conteúdo relacionado

Mais procurados

Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languagesVarun Garg
 
10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechz10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechzShahbaz Ahmad
 
Programming languages
Programming languagesProgramming languages
Programming languagesAsmasum
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2REHAN IJAZ
 
introduction computer programming languages
introduction computer programming languages introduction computer programming languages
introduction computer programming languages BakhatAli3
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentationfazli khaliq
 
Computer Science Class 11 India PPT
Computer Science Class 11 India PPTComputer Science Class 11 India PPT
Computer Science Class 11 India PPTRat Devil
 
pdf c programming language.pdf
pdf c programming language.pdfpdf c programming language.pdf
pdf c programming language.pdfVineethReddy560178
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer ProgrammingAllen de Castro
 
System Programming- Unit I
System Programming- Unit ISystem Programming- Unit I
System Programming- Unit ISaranya1702
 
High level and Low level Language
High level and Low level Language High level and Low level Language
High level and Low level Language adnan usmani
 

Mais procurados (20)

Introduction to qbasic
Introduction to qbasicIntroduction to qbasic
Introduction to qbasic
 
Computer languages 11
Computer languages 11Computer languages 11
Computer languages 11
 
Pascal programming language
Pascal programming languagePascal programming language
Pascal programming language
 
Programming
ProgrammingProgramming
Programming
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 
10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechz10th class computer science notes in english by cstechz
10th class computer science notes in english by cstechz
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
 
Qbasic program
Qbasic programQbasic program
Qbasic program
 
introduction computer programming languages
introduction computer programming languages introduction computer programming languages
introduction computer programming languages
 
Qbasic
QbasicQbasic
Qbasic
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentation
 
Computer programming
Computer programmingComputer programming
Computer programming
 
Computer Science Class 11 India PPT
Computer Science Class 11 India PPTComputer Science Class 11 India PPT
Computer Science Class 11 India PPT
 
pdf c programming language.pdf
pdf c programming language.pdfpdf c programming language.pdf
pdf c programming language.pdf
 
Introduction to problem solving in C
Introduction to problem solving in CIntroduction to problem solving in C
Introduction to problem solving in C
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer Programming
 
System Programming- Unit I
System Programming- Unit ISystem Programming- Unit I
System Programming- Unit I
 
I PUC CS Lab_programs
I PUC CS Lab_programsI PUC CS Lab_programs
I PUC CS Lab_programs
 
High level and Low level Language
High level and Low level Language High level and Low level Language
High level and Low level Language
 

Destaque

Destaque (16)

The Knowledge of QBasic
The Knowledge of QBasicThe Knowledge of QBasic
The Knowledge of QBasic
 
QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern Programming
 
QBASIC
QBASICQBASIC
QBASIC
 
Lec monitor
Lec monitorLec monitor
Lec monitor
 
Management information system Unit 1
Management information system Unit 1Management information system Unit 1
Management information system Unit 1
 
Mis 001
Mis 001Mis 001
Mis 001
 
Lecture 1 mis
Lecture 1  misLecture 1  mis
Lecture 1 mis
 
Lect 30 dbms_fundamentals
Lect 30  dbms_fundamentalsLect 30  dbms_fundamentals
Lect 30 dbms_fundamentals
 
Ch01
Ch01Ch01
Ch01
 
Lecture 11 bmbs management information system qs
Lecture 11 bmbs management information system   qsLecture 11 bmbs management information system   qs
Lecture 11 bmbs management information system qs
 
Ch02 mis-imp-concepts
Ch02 mis-imp-conceptsCh02 mis-imp-concepts
Ch02 mis-imp-concepts
 
Management information system
Management information systemManagement information system
Management information system
 
Laudon mis12 ppt01
Laudon mis12 ppt01Laudon mis12 ppt01
Laudon mis12 ppt01
 
MIS Chapter 1
MIS Chapter 1MIS Chapter 1
MIS Chapter 1
 
Mis lecture ppt
Mis lecture pptMis lecture ppt
Mis lecture ppt
 
Management Information System (Full Notes)
Management Information System (Full Notes)Management Information System (Full Notes)
Management Information System (Full Notes)
 

Semelhante a Qbasic tutorial

QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingGifty Belle Manaois
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language ProgrammingNiropam Das
 
Basic computer-programming-2
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2lemonmichelangelo
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programmingWondeson Emeye
 
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIIntro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIBlue Elephant Consulting
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGJEENA SARA VIJU
 
Tutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verQrembiezs Intruder
 
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1ILearn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1Ilivecoding.tv
 

Semelhante a Qbasic tutorial (20)

Computer programming k 12
Computer programming k 12Computer programming k 12
Computer programming k 12
 
QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern Programming
 
Assembly Language Programming
Assembly Language ProgrammingAssembly Language Programming
Assembly Language Programming
 
Basic computer-programming-2
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
 
Basic programming
Basic programmingBasic programming
Basic programming
 
Intro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample ProgramIntro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample Program
 
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIIntro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
 
programming.ppt
programming.pptprogramming.ppt
programming.ppt
 
Pascal programming lecture notes
Pascal programming lecture notesPascal programming lecture notes
Pascal programming lecture notes
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
The basics of c programming
The basics of c programmingThe basics of c programming
The basics of c programming
 
Tutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng verTutorial basic of c ++lesson 1 eng ver
Tutorial basic of c ++lesson 1 eng ver
 
C programming
C programmingC programming
C programming
 
Ch02.pdf
Ch02.pdfCh02.pdf
Ch02.pdf
 
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1ILearn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
 
Presentation 2.ppt
Presentation 2.pptPresentation 2.ppt
Presentation 2.ppt
 
Computer programming
Computer programmingComputer programming
Computer programming
 
Input-output
Input-outputInput-output
Input-output
 
A tutorial on C++ Programming
A tutorial on C++ ProgrammingA tutorial on C++ Programming
A tutorial on C++ Programming
 

Último

Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...amitlee9823
 
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证tufbav
 
Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Pooja Nehwal
 
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Introduction-to-4x4-SRAM-Memory-Block.pptx
Introduction-to-4x4-SRAM-Memory-Block.pptxIntroduction-to-4x4-SRAM-Memory-Block.pptx
Introduction-to-4x4-SRAM-Memory-Block.pptxJaiLegal
 
怎样办理圣芭芭拉分校毕业证(UCSB毕业证书)成绩单留信认证
怎样办理圣芭芭拉分校毕业证(UCSB毕业证书)成绩单留信认证怎样办理圣芭芭拉分校毕业证(UCSB毕业证书)成绩单留信认证
怎样办理圣芭芭拉分校毕业证(UCSB毕业证书)成绩单留信认证ehyxf
 
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Call Girls in Nagpur High Profile
 
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证tufbav
 
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证wpkuukw
 
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...amitlee9823
 
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)kojalkojal131
 
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...amitlee9823
 
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)amitlee9823
 
Call Girls In RT Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In RT Nagar ☎ 7737669865 🥵 Book Your One night StandCall Girls In RT Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In RT Nagar ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证wpkuukw
 

Último (20)

Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
Kothanur Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
 
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
 
Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006Call Girls in Vashi Escorts Services - 7738631006
Call Girls in Vashi Escorts Services - 7738631006
 
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Introduction-to-4x4-SRAM-Memory-Block.pptx
Introduction-to-4x4-SRAM-Memory-Block.pptxIntroduction-to-4x4-SRAM-Memory-Block.pptx
Introduction-to-4x4-SRAM-Memory-Block.pptx
 
怎样办理圣芭芭拉分校毕业证(UCSB毕业证书)成绩单留信认证
怎样办理圣芭芭拉分校毕业证(UCSB毕业证书)成绩单留信认证怎样办理圣芭芭拉分校毕业证(UCSB毕业证书)成绩单留信认证
怎样办理圣芭芭拉分校毕业证(UCSB毕业证书)成绩单留信认证
 
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
 
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Chakan ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
CHEAP Call Girls in Mayapuri (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Mayapuri  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Mayapuri  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Mayapuri (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
 
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证
一比一定(购)坎特伯雷大学毕业证(UC毕业证)成绩单学位证
 
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men  🔝kakinada🔝   Escor...
➥🔝 7737669865 🔝▻ kakinada Call-girls in Women Seeking Men 🔝kakinada🔝 Escor...
 
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
(=Towel) Dubai Call Girls O525547819 Call Girls In Dubai (Fav0r)
 
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Banashankari Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
 
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Call Girls In RT Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In RT Nagar ☎ 7737669865 🥵 Book Your One night StandCall Girls In RT Nagar ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In RT Nagar ☎ 7737669865 🥵 Book Your One night Stand
 
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
 

Qbasic tutorial

  • 1. Submitted by: Jovelle D. Luzon Dianne Myrell V. Sandoval Submitted to: Mr. Angel Corona
  • 2. BASIC stands for Beginner’s All Purpose Symbolic Introduction Code. It was invented in 1963, at Dartmouth Collage, by the mathematicians John George Kemeny and Tom Kurtzas. BASIC is an interpreter which means it reads every line, translates it and lets the computer execute it before reading another. Each instruction starts with a line number. INTRODUCTION TO QBASIC
  • 3. FEATURES OF QBASIC  It is a user friendly language.  It is widely known and accepted programming language.  It is one of the most flexible languages, as modification can easily be done in already existing program  Language is easy since the variable can be named easily and uses simple English phrases with mathematical expressions. RULES OF QBASIC Every programming language has a set of rules that have to be followed while writing a program, following are some rules of QBASIC language:  All QBasic programs are made up of series of statements, which are executed in the order in which they are written.  Every statement should have at least one QBasic command word. The words that BASIC recognizes are called keywords.  All the command words have to be written using some standard rules, which are called “Syntax Rules”. Syntax is the grammar of writing the statement in a language. Syntax Errors are generated when improper syntax is detected.
  • 4. QBASIC DATA Data is a collection of facts and figures that is entered into the computer through the keyboard. Data is of two types: CONSTANT: Data whose value does not change or remains fixed. There are two types of constants:  (a) NUMERIC CONSTANT: Numbers – negative or positive used for mathematical calculations. e.g. -10, 20, 0 (b) ALPHANUMERIC CONSTANT/STRING: Numbers or alphabets written within double quotes(inverted commas “ “). e.g. “Computer”, “Operating System” VARIABLE: Data whose value is not constant and may change due to some calculation during the program execution. There are two types of variables.  (a) NUMERIC VARIABLE: The value that holds a Numeric Constant for arithmetic calculations (+, -, *, /) is called a Numeric Variable. e.g. A = 50, here A is the Numeric Variable (b) ALPHANUMERIC VARIABLE: Cannot be used for arithmetic calculations. Alphanumeric Number must end with a $ sign and must be enclosed in inverted commas. e.g. Name$ = “Akanksha”, here Name$ is an Alphanumeric Variable.
  • 5. Once QBASIC PROGRAM is loaded into the computer memory, it displays Ok prompt. Ok means it already to accept the commands. QBASIC can be made to translate your instructions in two modes: Direct Mode Program Mode 1. Direct Mode: The accepts single line instructions from the user and the output is viewed as soon as enter key is pressed. The instructions are not stored in the memory. This mode can be used to do quick calculation. They do not have lines. E.g. Print 3+4 Print “This is the Direct mode in QBasic” 2. Program Mode: The mode is used to type a program which is stored in the memory. They have line numbers. We have to give the command to get the output. e.g. 10 Print 3+4 20 End RUN Programs are built up with set of instructions or commands. Every programming language has its own SYNTAX (rules) and COMMANDS. TYPES OF MODE IN QBASIC
  • 6. The following commands do not need line number. LIST- the command is used to list the program on the screen. RUN- the command is used to execute the program. LLIST- the command is used to list of program as a hardcopy. LPRINT- the command is used to get the output of the program on the hardcopy. NEW- the command is used clear the memory of the existing program. SYSTEM- the command is used to take you back to dos prompt. PRINT AND CLS- the command cam also be used without a line number. Print is used to view the display on the screen and CLS to clear the screen. RME- the command is used to show the position of the mistake. SAVE- the keyword is used to save the program. LOAD- the keyword is used to LOAD the program from the disk to the memory. COMMAND/KEYWORDS IN QBASIC AND THEIR FUNCTIONS
  • 7. 1. CLS: This command is used to clear the screen. 2. PRINT: Print command is used to display the output on the screen. E.g. Print “HELLO WORLD!!!” Print 80 * 8 Print Tab(10) “Navrachana”- will print Navrachana on 10 column. 3.REM: Stands for Remark. It gives an explanation of the program or of the statements in the program more understandable to the reader. 4. LET: It assigns a value to a variable in a program. It stores value in the memory location. QBASIC COMMANDS
  • 8.  SYNTAX: Let <Variable>=<Constant/Variable or Expression> e.g. Let A = 15……..Assigning constant to a variable Let A = B……..Assigning variable to a variable LET C = A+B….Assigning an expression to a variable Using Let with Numeric Variables: Let A = 50, here A is a Numeric Variable and ‘50’ is a Numeric Constant and the value ‘50’ is assigned to a and stored in the computer’s memory for further calculations. Using Let with Alphanumeric Variable: Let N$ = “QBasic Program”, here N$ is an Alphanumeric Variable and “QBasic Program” is the Alphanumeric Constant assigned to N$.
  • 9. Note: A numeric data should be assigned to a Numeric variable and an alphanumeric data to an alphanumeric variable otherwise “TYPE MISMATCH” error is displayed. 5. END- This command is usually given at the end of the program. 6.INPUT: This statement allows the user to enter a value for the variable while running the program. SYNTAX: INPUT <VARIABLE> e.g. Input A…..Enter Numeric constant Input N$.....Enter Alphanumeric constant Input “Enter name:”;N$.....Giving relevant message to avoid erroneous data input
  • 10. 7. DELETE <LINE NO.>: To delete a line number in a program. e.g. Delete 10 will delete line number 10 Delete 30-50 will delete all the line between 30 to 50. Print with Comma (,): The screen of the computer is made of 80 columns and 40 rows. The columns are divided into five (5) zones 14 columns each. Comma placed after the message prints the message zone wise on the screen. Print with Semi-Colon (;) Semi-Colon placed after the message to be displayed, leaves no space between two messages. e.g. Print “This is an example”;” of QBasic program” Output: This is an example of QBasic program
  • 11. QBASIC REMINDER A QBASIC program consists of lines containing 1. A line number 2. A QBASIC keyword like PRINT ,END etc 3. Each program line begins with positive number. 4. No two lines should ha same number. RUNNING A PROGRAM RUN is the command used to execute the program and get the output on the screen. WRTING A NEW PROGRAM It is possible to overwrite lines with a new statements, but if you want to write a totally new program use a NEW command. EXITING QBASIC In order to exit the QBASIC program SYSTEM command is used.
  • 12. There are also special functions called “commands” (also called “instructor”). A “command” tells the QBasic interpreter to do something. The PRINT command tells the QBasic interpreter to print something to the screen. In this case, the interpreter printed “Hello World!”. With the PRINT command, you can also print numbers to the screen. Delete the current program (unless you already have) and write the following: PRINT 512 (or ?512) <press Enter> Press F5 to run the program. The program outputs: 512 COMMANDS TIPS: Instead of typing PRINT, you can enter a question mark. For example: ?”Hello World!”
  • 13. An expression is something the interpreter calculates (evaluates). Such as: 1 + 1 ( returns 2) 100 – 47 ( returns 53) 3 + 34 ( returns 102 ) 80 / 4 ( returns 20 ) ( 100 * 3 ) + 56 ( returns 356 ) EXPRESSIONS NOTE: The asterisk ( * ) means to multiply two numbers; the slash ( / ) means to divide
  • 14.  If you pass an expression to the PRINT command, the value returned (a number) is printed. Clear the current program, and then run the following: PRINT 512 + 478 Program output: 990 IF you enclose the expression with quotation marks, the expression becomes a string and isn’t evaluated. For example: PRINT “512 + 478” Output: 512 + 478 TIP: To clear the output screen, use the CLS command.
  • 15. You can use multiple print statements in your program. PRINT “Hello” PRINT “World” Output: Hello World To place World onto the previous line, place a semi-colon after PRINT “Hello”. PRINT “Hello”; PRINT “World” Output: HelloWorld Also, if you put a comma instead of a semi-colon on the first line, the program will insert spaces between the two words. PRINT “Hello”, PRINT “World” Output: Hello World More about the PRINT command
  • 16. This chapter discusses an important topic in programming, “variables.” Please read this section thoroughly. A variable is a piece of data kept in the computer’s memory (RAM). The location of a variable in RAM is called the “address.” Variables Memory address Value 999997 0 999998 0 999999 0 1000000 0 1000001 0 1000002 0 1000003 0 Variable
  • 17.  How a variable is stored in RAM The following program prints the variable x to the screen. print x Since the variable hasn’t been assigned a number, the value of the variable is 0. So, the output of the program is: 0 The next program sets x to15, and then prints the variable: x = 15 print x The time, the output is: 15
  • 18.  In the above example, the number 15 was stored in the computer’s RAM at a certain memory address. Then the PRINT command accessed (or looked at) that address when it printed “15” to the screen. Memory address Value 999997 0 999998 0 999999 0 1000000 0 1000001 0 1000002 0 1000003 0 Variable X
  • 19.  (NOTE: The memory address of x is not necessarily 1000000) As in the program above, a variable is accesses by calling its name. Variable names can have a combination of letters and numbers. The following are valid variables: Y num VALUE xYz abc123 ADVANCED TIP: Although you don’t normally need to, you can find the actual memory address of a variable (x, for example) by using the VARSEG and VARPTR commands. PRINT (VARSEG(X) * VARPTR(X)
  • 20. One way to receive input from the keyboard is with the INPUT command. The INPUT command allows the user to enter either a string or a number, which is then stored in a variable. INPUT data$ PRINT data$ When this program is executed, the INPUT command displays a question mark, followed by a blinking cursor. And when you enter text, the program stores that text into the variable data$, which is printed to the screen. Retrieving Keybord input from the user TIP: If you place a string and a semi-colon between INPUT and the variable, the program will print the string. INPUT “Enter some text:”; data$
  • 21. To receive a number, use non-string variable. INPUT number PRINT number If you enter text instead of a number, the Qbasic interpreter displays an error message ( “Redo from start “ ). Below is another example of the INPUT command: PRINT “ Enter some text : “ INPUT text$ PRINT “ Now enter a number : “ INPUT num PRINT text$ PRINT num TIP: you can have the question mark displayed on the previous line by using a semi-colon. PRINT “ Enter some text:”; INPUT text$
  • 22. The IF and THEN commands are used to compare an expression and then perform some task based on that expression. x = 5 IF x = 5 THEN PRINT “ equals 5 “ Since x does equal 5 in this case, the program outputs: x equals 5 The IF and THEN commands
  • 23. You can also enter the following statements, instead of the equals sign: x < 5 (x is less than 5) x > 5 (x is greater than 5) Run the following: x = 16 IF (x > 5) THEN PRINT “x is greater than 5” Ouput: x is greater than 5 Expression signs
  • 24. You can also combine the signs like this: x <= 5 (x is less than or equal to 5) x >= 5 (x is greater than or equal to 5) x <> 5 (x does not equal 5) Run the following example: CLS x = 5 IF (x >= 5) THEN PRINT “x is greater than or equal to 5” IF (x <= 5) THEN PRINT “x is less than or equal to 5” IF (x <> 5) THEN PRINT “x does not equal to 5” Output: x is greater than or equal to 5 x is less than or equal to 5
  • 25.   Using the ELSE command, you can have the program perform a different action if the statement is false. x = 3 IF x = 5 THEN PRINT “Yes” ELSE PRINT “No” Since x doesn’t equal 5, the output is: No ELSE
  • 26.  END IF allows you to have multiple commands after the IF. . .THEN statement, but they must start on the line after the IF statement. END IF should appear right after the list of commands. x = 5 IF (x = 5) THEN INPUT a$ PRINT a$ END IF The following program uses ELSE with the END IF command: x = 16 IF (x = 5) THEN INPUT a$ PRINT a$ ELSE PRINT x * 2 END IF Output: 32 END IF TIP: There is a way to have multiple commands after IF. . .THEN without using END IF. To do so, place a colon between each command. IF (x = 5) THEN PRINT a$: PRINT a$
  • 27. The ELSEIF command allows you to perform a secondary action if the first expression was false. Unlike ELSE, this task is only performed if specified statement is true. x = 6 IF ( x = 6 ) THEN PRINT “ Statement 1 is true “ ELSEIF ( x = 6 ) THEN PRINT “ Statement 2 is true “ ENDIF Output: Statement 2 is true You can have multiple ELSEIF commands, along with ELSE. x = 8 IF (x = 5) THEN PRINT “Statement 1 is true” ELSEIF (x = 6) THEN PRINT “Statement 2 is true” ELSEIF (x = 7) THEN PRINT “Statement 3 is true” ELSE PRINT “No above statement are true” END IF Output: No above statements are true ELSEIF
  • 28. You can have more than one expression in IF. . .THEN by using either the OR operator or the AND operator. The OR operator only requires one expression to be true in order to print “Yes” in the following program: x = 20 IF (x = 5 OR x = 20) THEN PRINT “Yes” Output: Yes The AND operator requires both expressions to be true. x = 7 IF (x > 5 AND x < 10) THEN PRINT “True” Output: True This is a slightly more complex examples: x = 16 y = 3 IF ((x > 5 AND x < 10) OR y = 3) THEN PRINT “Correct” Output (since Y is 3): Correct Multiple expressions
  • 29.  So far this chapter, we’ve only been dealing with numbers, but you can also use strings with the IF. . .THEN command. x$ = “Hello” IF (x$ = “Hello” OR x$ = “World”) THEN PRINT x$ Output: Hello Strings in IF. . .THEN