SlideShare a Scribd company logo
Chapter I
Basic Commands
When you open QBasic, you see a blue screen where you can type your program.
Let’s begin with the basic commands that are important in any program.
PRINT
Command PRINT displays text or numbers on the screen.
The program line looks like this:
PRINT "My name is Nick."
Type the highlighted text into QBasic and press F5 to run the program. On the screen you’ll
see:
My name is Nick.
You must put the text in quotes, like this – "text". The text in quotes is called a string. If you
put the PRINT alone, without any text, it will just put an empty line. PRINT can also put
numbers on the screen. PRINT 57 will show the number 57. This command is useful for
displaying the result of mathematical calculations. But for calculations, as well as for other
things in the program, you need to use variables.
Variables
When you think, you keep words or numbers in your mind. This allows you to speak and to
make calculations. QBasic also needs to keep words or numbers in its memory. To do this,
you use variables, pieces of QBasic memory, which can keep information. A variable can be
named with any letter, for example – a. It can also have a longer name, which can be almost
any word. It is important to know that there are two main types of variables – that keep a
number and that keep a word or a string of words.
Numeric variables. It’s basically variables named with just a letter or a word. You tell this
variable to keep a number like this:
a = 15
In other words, you assigned the value 15 to the variable a.
QBasic will now know that the variable named a keeps the number 15. Now, if you type:
PRINT a
and run the program, the computer will show this number on the screen.
String variables can keep so called "strings", which is basically any text or symbols (like % or
£), which you put in the quotes "". You can also put numbers in a string variable, but again, you
must include them in quotes, and QBasic will think that those numbers are just a part of text.
The string variables look like this – a$. The $ sign tells QBasic that this variable contains text.
Example:
a$ = "It is nice to see you"
PRINT a$
On the screen you’ll see:
It is nice to see you
The PRINT command can print more that one string on the line. To do this, put the ; sign
between the variables. For example, you have two variables – name$, which contains name
Rob, and age, which contains the number 34. Then, to print both name and age, you type:
PRINT "Name - "; name$; ". Age - "; age
As you can see, the name of a variable can be more than just one letter – it can be a short
word which describes what sort of information does this variable keep.
What you see on the screen when you run the program will look like this:
Name – Rob. Age – 34
Or, you can type the program like that:
PRINT "Name - "; name$
PRINT "Age - "; age
The result is:
Name – Rob
Age – 34
INPUT
INPUT is a command that allows you or anybody else who runs the program to enter the
information (text or number) when the program is already running. This command waits for
the user to enter the information and then assigns this information to a variable. Since there
are two types of variables, the INPUT command may look like this – INPUT a (for a
number), or INPUT a$ (for a string).
Example (Type this program into QBasic and run it by pressing F5)
PRINT "What is your name?"
INPUT name$
PRINT "Hi, "; name$; ", nice to see you!"
PRINT "How old are you?"
INPUT age
PRINT "So you are "; age; " years old!"
END
The END command tells QBasic that the program ends here.
You don’t have to use PRINT to ask the user to enter the information. Instead, you can use
INPUT "Enter your name"; name$
and the result will be the same.
GOTO
Quite often you don’t want the program to run exactly in the order you put the lines, from the
first to the last. Sometimes you want the program to jump to a particular line. For example,
your program asks the user to guess a particular number:
~ ~ ~ ~ 'some of the program here
INPUT "Guess the number"; n
~ ~ ~ ~ 'some of the program there
The program then checks if the entered number is correct. But if the user gives the wrong
answer, you may want to let him try again. So you use the command GOTO, which moves
the program back to the line where the question is asked. But first, to show QBasic where to
go, you must "label" that line with a number:
1 INPUT "Guess the number"; n 'this line is
labelled with number 1
Then, when you want the program to return to that line, you type
GOTO 1
You can use GOTO to jump not only back but also forward, to any line you want. Always
remember to label that line. You can have more than one label, but in that case they should
be different.

More Related Content

What's hot

The Knowledge of QBasic
The Knowledge of QBasicThe Knowledge of QBasic
The Knowledge of QBasic
Enelrah Vanna Dela Cruz
 
Qbasic Interface
Qbasic InterfaceQbasic Interface
Qbasic Interface
foreverflrst
 
Qbasic notes
Qbasic notesQbasic notes
Qbasic notes
NasirRohail1
 
QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern Programming
Gifty Belle Manaois
 
Modular programming in qbasic
Modular programming in qbasicModular programming in qbasic
Modular programming in qbasic
Cavite National Science High School
 
Pseudocode
PseudocodePseudocode
Pseudocode
Harsha Madushanka
 
Algorithm and psuedocode
Algorithm and psuedocodeAlgorithm and psuedocode
Algorithm and psuedocode
Mustafa Qureshi
 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithmshccit
 
Pseudocode
PseudocodePseudocode
Pseudocode
grahamwell
 
C++basics
C++basicsC++basics
C++basics
amna izzat
 
Simple perl scripts
Simple perl scriptsSimple perl scripts
Simple perl scripts
University High School - Fresno
 
pseudocode and Flowchart
pseudocode and Flowchartpseudocode and Flowchart
pseudocode and Flowchart
ALI RAZA
 
Unit 3 Foc
Unit  3 FocUnit  3 Foc
Unit 3 Foc
JAYA
 
5 structured programming
5 structured programming 5 structured programming
5 structured programming hccit
 
Pseudocode & flowchart examples
Pseudocode & flowchart examplesPseudocode & flowchart examples
Pseudocode & flowchart examples
hayrikk
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codeshermiraguilar
 
Basic computer-programming-2
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2
lemonmichelangelo
 

What's hot (19)

The Knowledge of QBasic
The Knowledge of QBasicThe Knowledge of QBasic
The Knowledge of QBasic
 
Qbasic Interface
Qbasic InterfaceQbasic Interface
Qbasic Interface
 
Qbasic notes
Qbasic notesQbasic notes
Qbasic notes
 
QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern Programming
 
Computer programming k 12
Computer programming k 12Computer programming k 12
Computer programming k 12
 
Modular programming in qbasic
Modular programming in qbasicModular programming in qbasic
Modular programming in qbasic
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
Algorithm and psuedocode
Algorithm and psuedocodeAlgorithm and psuedocode
Algorithm and psuedocode
 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithms
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
C++basics
C++basicsC++basics
C++basics
 
Simple perl scripts
Simple perl scriptsSimple perl scripts
Simple perl scripts
 
pseudocode and Flowchart
pseudocode and Flowchartpseudocode and Flowchart
pseudocode and Flowchart
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Unit 3 Foc
Unit  3 FocUnit  3 Foc
Unit 3 Foc
 
5 structured programming
5 structured programming 5 structured programming
5 structured programming
 
Pseudocode & flowchart examples
Pseudocode & flowchart examplesPseudocode & flowchart examples
Pseudocode & flowchart examples
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 
Basic computer-programming-2
Basic computer-programming-2Basic computer-programming-2
Basic computer-programming-2
 

Similar to Q basic ch

Calculator 2
Calculator 2Calculator 2
Calculator 2livecode
 
QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern Programming
Gifty Belle Manaois
 
Chapter 2- Prog101.ppt
Chapter 2- Prog101.pptChapter 2- Prog101.ppt
Chapter 2- Prog101.ppt
JosephObadiahTuray
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
Bagzzz
 
Calculator 1
Calculator 1Calculator 1
Calculator 1livecode
 
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
livecoding.tv
 
C_Lab Manual_Part A.docx
C_Lab Manual_Part A.docxC_Lab Manual_Part A.docx
C_Lab Manual_Part A.docx
Pandiya Rajan
 
Ubuntu Terminal
Ubuntu TerminalUbuntu Terminal
Ubuntu Terminal
Cathy Woods
 
Using Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsUsing Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart Symbols
Ar Kyu Dee
 
Simplified c++ 40 programs
Simplified c++ 40 programsSimplified c++ 40 programs
Simplified c++ 40 programs
MoTechInc
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer Programming
Allen de Castro
 
Using Applications in Windows - R.D.Sivakumar
Using Applications in Windows - R.D.SivakumarUsing Applications in Windows - R.D.Sivakumar
Using Applications in Windows - R.D.Sivakumar
Sivakumar R D .
 
Debugger Of Turbo C
Debugger Of Turbo CDebugger Of Turbo C
Debugger Of Turbo C
mohit2501
 
gdscpython.pdf
gdscpython.pdfgdscpython.pdf
gdscpython.pdf
workvishalkumarmahat
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for Kids
Aimee Maree Forsstrom
 
Learning R while exploring statistics
Learning R while exploring statisticsLearning R while exploring statistics
Learning R while exploring statistics
Dorothy Bishop
 
A simple project of computer program.docx
A simple project of computer program.docxA simple project of computer program.docx
A simple project of computer program.docx
write4
 

Similar to Q basic ch (20)

Calculator 2
Calculator 2Calculator 2
Calculator 2
 
QBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern ProgrammingQBASIC: A Tool For Modern Programming
QBASIC: A Tool For Modern Programming
 
Chapter 2- Prog101.ppt
Chapter 2- Prog101.pptChapter 2- Prog101.ppt
Chapter 2- Prog101.ppt
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
 
Calculator 1
Calculator 1Calculator 1
Calculator 1
 
programming.ppt
programming.pptprogramming.ppt
programming.ppt
 
Project two c++ tutorial
Project two c++ tutorialProject two c++ tutorial
Project two c++ tutorial
 
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
 
Chap3
Chap3Chap3
Chap3
 
C_Lab Manual_Part A.docx
C_Lab Manual_Part A.docxC_Lab Manual_Part A.docx
C_Lab Manual_Part A.docx
 
Ubuntu Terminal
Ubuntu TerminalUbuntu Terminal
Ubuntu Terminal
 
Using Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart SymbolsUsing Pseudocode Statements and Flowchart Symbols
Using Pseudocode Statements and Flowchart Symbols
 
Simplified c++ 40 programs
Simplified c++ 40 programsSimplified c++ 40 programs
Simplified c++ 40 programs
 
Basic Computer Programming
Basic Computer ProgrammingBasic Computer Programming
Basic Computer Programming
 
Using Applications in Windows - R.D.Sivakumar
Using Applications in Windows - R.D.SivakumarUsing Applications in Windows - R.D.Sivakumar
Using Applications in Windows - R.D.Sivakumar
 
Debugger Of Turbo C
Debugger Of Turbo CDebugger Of Turbo C
Debugger Of Turbo C
 
gdscpython.pdf
gdscpython.pdfgdscpython.pdf
gdscpython.pdf
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for Kids
 
Learning R while exploring statistics
Learning R while exploring statisticsLearning R while exploring statistics
Learning R while exploring statistics
 
A simple project of computer program.docx
A simple project of computer program.docxA simple project of computer program.docx
A simple project of computer program.docx
 

Recently uploaded

The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
AG2 Design
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Ashish Kohli
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 

Recently uploaded (20)

The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 

Q basic ch

  • 1. Chapter I Basic Commands When you open QBasic, you see a blue screen where you can type your program. Let’s begin with the basic commands that are important in any program. PRINT Command PRINT displays text or numbers on the screen. The program line looks like this: PRINT "My name is Nick." Type the highlighted text into QBasic and press F5 to run the program. On the screen you’ll see: My name is Nick. You must put the text in quotes, like this – "text". The text in quotes is called a string. If you put the PRINT alone, without any text, it will just put an empty line. PRINT can also put numbers on the screen. PRINT 57 will show the number 57. This command is useful for displaying the result of mathematical calculations. But for calculations, as well as for other things in the program, you need to use variables. Variables When you think, you keep words or numbers in your mind. This allows you to speak and to make calculations. QBasic also needs to keep words or numbers in its memory. To do this, you use variables, pieces of QBasic memory, which can keep information. A variable can be named with any letter, for example – a. It can also have a longer name, which can be almost any word. It is important to know that there are two main types of variables – that keep a number and that keep a word or a string of words. Numeric variables. It’s basically variables named with just a letter or a word. You tell this variable to keep a number like this:
  • 2. a = 15 In other words, you assigned the value 15 to the variable a. QBasic will now know that the variable named a keeps the number 15. Now, if you type: PRINT a and run the program, the computer will show this number on the screen. String variables can keep so called "strings", which is basically any text or symbols (like % or £), which you put in the quotes "". You can also put numbers in a string variable, but again, you must include them in quotes, and QBasic will think that those numbers are just a part of text. The string variables look like this – a$. The $ sign tells QBasic that this variable contains text. Example: a$ = "It is nice to see you" PRINT a$ On the screen you’ll see: It is nice to see you The PRINT command can print more that one string on the line. To do this, put the ; sign between the variables. For example, you have two variables – name$, which contains name Rob, and age, which contains the number 34. Then, to print both name and age, you type: PRINT "Name - "; name$; ". Age - "; age As you can see, the name of a variable can be more than just one letter – it can be a short word which describes what sort of information does this variable keep.
  • 3. What you see on the screen when you run the program will look like this: Name – Rob. Age – 34 Or, you can type the program like that: PRINT "Name - "; name$ PRINT "Age - "; age The result is: Name – Rob Age – 34 INPUT INPUT is a command that allows you or anybody else who runs the program to enter the information (text or number) when the program is already running. This command waits for the user to enter the information and then assigns this information to a variable. Since there are two types of variables, the INPUT command may look like this – INPUT a (for a number), or INPUT a$ (for a string). Example (Type this program into QBasic and run it by pressing F5) PRINT "What is your name?" INPUT name$ PRINT "Hi, "; name$; ", nice to see you!"
  • 4. PRINT "How old are you?" INPUT age PRINT "So you are "; age; " years old!" END The END command tells QBasic that the program ends here. You don’t have to use PRINT to ask the user to enter the information. Instead, you can use INPUT "Enter your name"; name$ and the result will be the same. GOTO Quite often you don’t want the program to run exactly in the order you put the lines, from the first to the last. Sometimes you want the program to jump to a particular line. For example, your program asks the user to guess a particular number: ~ ~ ~ ~ 'some of the program here INPUT "Guess the number"; n ~ ~ ~ ~ 'some of the program there The program then checks if the entered number is correct. But if the user gives the wrong answer, you may want to let him try again. So you use the command GOTO, which moves the program back to the line where the question is asked. But first, to show QBasic where to go, you must "label" that line with a number: 1 INPUT "Guess the number"; n 'this line is labelled with number 1
  • 5. Then, when you want the program to return to that line, you type GOTO 1 You can use GOTO to jump not only back but also forward, to any line you want. Always remember to label that line. You can have more than one label, but in that case they should be different.