Address
:
[go:
up one dir
,
main page
]
Include Form
Remove Scripts
Session Cookies
Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
100%
(1)
100% found this document useful (1 vote)
98 views
8 pages
Chapter4QBasic ProgrammingStatements
Uploaded by
vaishnavimadan
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Chapter4QBasic-ProgrammingStatements For Later
Download
Save
Save Chapter4QBasic-ProgrammingStatements For Later
100%
100% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
100%
(1)
100% found this document useful (1 vote)
98 views
8 pages
Chapter4QBasic ProgrammingStatements
Uploaded by
vaishnavimadan
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Chapter4QBasic-ProgrammingStatements For Later
Carousel Previous
Carousel Next
Download
Save
Save Chapter4QBasic-ProgrammingStatements For Later
100%
100% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 8
Search
Fullscreen
SNAP/RECAP Programming statements can be sequential, conditional or iterational. IP... THEN ... ELSE is used to execute a statement based on a condition. END IF is given to end the IF statement. ; ELSEIF allows executing a set of statements if the previous condition is false. 1 2 3. 4. CEARNING OBJECTIVES You will learn about: 1. FOR... NEXT 4. WHILE ... WEND 2. DO WHILE ... LOOP 5. EXIT Command 3. DO UNTIL... LOOP Introduction - Sometimes there is a need to repeat a set of statements more than once based on a certain Condition. This process of repetition is called Loop or Iteration in programming, A loop is, thus, used to repeat a block of statements a specific number of. time: loops are available in QBASIC: + DO WHILE... LOOP + FOR... NEXT + WHILE ... WEND * DO UNTIL... LOOP s. The following The FOR statements are best used to perform a loop a specific number of times, However, the DO ... and WHILE ... WEND statements are best used to perform a loop an undetermined number of times. Scanned with CamScannerFOR ... NEXT FOR ... NEXT structure is used when you want to perform a loop a specific nurmber of times, Ieuses a counter variable which is incremented or decremented with each repetition of the Joop. Syntax RK counter_variable = Start Value TO End Value S' StepValue Statement2; counter_variable ‘The explanation of the syntax is given below: + FOR statement is the beginnin of the loop. StartValue is the initial value of the counter_variable. EndValue is the value that the counter_variable must exceed to exit the loop. StepValue is the amount by which the counter is changed each time through the loop. NEXT statement is the end of the loop. STEP statement is given to specify the StepValue. If not specified, STEP defaults to one. This value can be either positive (when counter increases) or negative (when counter deer s). After all the statements in the loop have been executed, Step Value is added to the counter. At this value point, either the statements in the loop execute again (based on the same test that caused the loop to execute initially), or the foop is exited and execution continues with the statement following the NEXT statement. Sample Program 1:To print multiples of 5 from 0 to 30 The input and the corresponding output for Sample Program | is given in Table 4.1. ‘Table 4.1 Input - Output CLs 0 FORA =0TO 30 STEP 5S 5 PRINTA 10 NEXTA 15 20 25 30 a a eet} | tl Or) LD Scanned with CamScannerSe Sample in 1 and 10 Pi : betwee Togram 2:To display even numbers 0° given in Table 4.2, The i mput svowram 2 Patand the corresponding output for Sample Progra" 4 — Output Ree Table 4.2 np cLs ay FOR As PRINT A NEXT A TO9 st a ae Tf you w: , You want to create a countdown loop where the number is decremented with each loop simply use a negati ‘ative StepValue as shown in the following example. Sam ; — wie Program 3: To display countdown from 10 to 1 put and the corresponding output for Sample Program 3 is given in Table 4.3. i Table 4.3 Input — Output cLs 0 FORA =10TO1 STEP-1 9 PRINT A ' NEXTA 7 6 5 4 3 2 1 GD» na decrementing loop the starting number is greater tha i ae n the ending number Tr. A. t the square of numbers from 1 to 10 using FOR ... NEXT | ce loop. B. Print the odd numbers from 20 to 1 using FOR ++ NEXT loop, a eo Bae Scanned with CamScannerDO WHILE . LOOP 3 ... LOOP is performed as long : PeaA ements written within DO ... LOOP will be repeated till the condition is true, Every loop ends with the LOOP statement. Before the loop is ended, the counter variable must be incremented or decremented to avoid an infinite loop. A counter variable is used to control execution of a DO WHILE ... loop. It increments/ decrements each time through the loop. and is tested in the loop expression. A counter is good to use when you specifically know how many times you need to execute the loop. For example, in DO WHILE ... loop in Sample Program 1 count is used as a counter. Syntax DO WHILE test condition Statement! Statement2 as the condition being tested is true. It means LOOP Sample Program 4:To print numbers 1 to 10 The input and the corresponding output of Sample Program 4 is given in Table 4.4. ° cLs 1 count = 1 2 DOWHILE coump<= 19g ot 3 count =count +P —~ Pv ral Coun 4 LOOP 5 6 7 8 9 10 Try and observe the output for the as Try and observe the output for the following: a following: az! LETa=1 DO WHILE a>= 1 DO WHILE a<=10 PRINT a PRINT a+a aza-l Earl LOOP LOO! Scanned with CamScannerDO UNTIL aie atements until the condition Do ist UNTIL ... is different from DO WHILE... as it executes the st it exits the loop if Tue. In other words, it executes the statement if the condition is false and it ex , the condition is true, Syntax DO UNTIL test condition Statement! Statement2 LOOP Let us write a sample program using DO UNTIL ... LOOP. Sample Program 5: To print numbers 1 to 9 ‘The input and the corresponding output of Sample Program 5 is given in Table 4.5. Table 4.5 Input - Output a | CLs count = | veTze DO WHEE count = 10 count = count #1 Loop ——— Print count Coed Anew ne D> 10 is not printed in this program as the statements get executed only till the condition is false. As soon as the value of count becomes 10, statement is true and the Joop ends. WHILE ... WEND While...wend works just like any other loop. It executes a series of statements as long as specified condition is true. Syntax WHILE test condition Statements WEND a Ba Scanned with CamScannerSample program 6: To generate multiples of 5 from 5 to 50 The input and the corresponding output of Sample Program 6 is given in Table 4.6, Table 4.6 Input - Output cLs 5 LET num =5 10 WHILE num <=50 15 PRINT num 20 num = num +5 25 WEND 30 © 35 40 45 50 EXIT Exit command is used to come out of a loop before the expected number of executions. EXIT command is used followed by either FOR or DO. Sample Program 7: To exit after 3 while printing 1 to 5 ‘The input and the corresponding output of Sample Program 7 is given in Table 4.7. Table 4.7 Input - Ouput Lie > a Sa cLs FORM=1TOS PRINT M,esptatttd IF M=3 THEN EXIT FOR wre NEXT M A. Print multiples of 10 from 10 to 100 using WHILE ... WEND. B. Print the sum of 1 to 5 natural numbers using DO WHILE ... LOOP.+ The FOR ... NEXT structure is used when you want to perform! pe number of times. It uses counter variable which is incremented Or with each repetition of the loop. . + ADO WHILE... LOOP is performed as long as the conditio + DO... UNTIL LOOP is different from DO WHILE as it executes the statements until the condition is true. + The purpose of DO ... LOOP and WHILE ... WEND is similar except for the syntax. + To come out of a loop before the expected number of execution, is used followed by either FOR or DO. n being tested is true. EXIT command € @ Fillinthe blanks. 1. FOR... NEXTisa type of QBASIC Statement. is used to end DO loop. works similar to DO ... WHILE. is used to repeat certain steps a fixed number of times. 2. 3 4, 5. The DO... LOOP can be used either with WHILE statement or .. statement. : © Answer the following questions. : 1. Whatis an iteration in QBASIC? Give examples. When do you use FOR... NEXT? Write a small code to support your answer What is the purpose of WHILE ... WEND in QBASIC? Write a small code. latnhababbaeahaehcadanheanteateahetaabtabenbalobtebtnahstehatesbteen” What is the difference between a DO WHILE and a DO UNTIL statement? Why do you use EXIT command? Give example. Scanned with CamScanner@ Find out the errors in the following programs: 41> 1 A=1 2. FORX=10T01 DO UNTILA <= 10 PRINT X PRINT A x A=A+1 LOOP Loop © © Give the output of the following programs: 1. TEACHER'S NOTES Tell the students that two loops can be used together. We can Nest one loop inside another. The outside Joop is evaluated first and then the nested loop is processed and evaluated. Demonstrate with an example. cls 2. M=1 FORY=1TO50step5 DO until M>=10 PRINT Y, Print M NEXTY M=M+1 LOOP .. Sarah wants to generate an even number series from 10 to 20, Which loop should she use? Write the code for this program. Write program to generate an odd number series from . Rita has been given a task of writing the multiples of 7 statements should she write to display these on the QBASIC screen? STEP -1 100 to 130. from 70 to 140. What @ Scanned with CamScanner
You might also like
Class 6 Chapter 6 Introduction To HTML
PDF
80% (5)
Class 6 Chapter 6 Introduction To HTML
6 pages
Airthmetic Progression
PDF
No ratings yet
Airthmetic Progression
15 pages
Unit III C Programming
PDF
No ratings yet
Unit III C Programming
88 pages
9th Science Mcqs PTB PDF
PDF
No ratings yet
9th Science Mcqs PTB PDF
25 pages
Safety and Security Worksheet Answer 2
PDF
No ratings yet
Safety and Security Worksheet Answer 2
18 pages
Squares and Square Roots
PDF
No ratings yet
Squares and Square Roots
41 pages
Cbse Class 9 Maths Notes Chapter 1 Number System
PDF
No ratings yet
Cbse Class 9 Maths Notes Chapter 1 Number System
4 pages
Introduction To Graphs Handout & Worksheet
PDF
No ratings yet
Introduction To Graphs Handout & Worksheet
6 pages
Exercise 1.3: NCERT Solutions For Class 9 Maths Chapter 1-Number System
PDF
No ratings yet
Exercise 1.3: NCERT Solutions For Class 9 Maths Chapter 1-Number System
7 pages
Class 3
PDF
No ratings yet
Class 3
11 pages
Linear Equations in One Variable r1
PDF
No ratings yet
Linear Equations in One Variable r1
21 pages
CL-9, Notes On Number System
PDF
No ratings yet
CL-9, Notes On Number System
5 pages
B8-Conservation of Plants and Animals
PDF
No ratings yet
B8-Conservation of Plants and Animals
68 pages
Class X Resource Material
PDF
No ratings yet
Class X Resource Material
234 pages
Assignment Real Numbers Class X: Answers
PDF
No ratings yet
Assignment Real Numbers Class X: Answers
1 page
Class-Vi (Chapter-10) Motion and Measurment of Distances Answers
PDF
No ratings yet
Class-Vi (Chapter-10) Motion and Measurment of Distances Answers
1 page
Class 8 Maths Formula Chapter 11 PDF
PDF
No ratings yet
Class 8 Maths Formula Chapter 11 PDF
4 pages
Science Class 7 Notes
PDF
No ratings yet
Science Class 7 Notes
11 pages
Diversity in Living Organisms
PDF
No ratings yet
Diversity in Living Organisms
7 pages
Class 5 EM Model Question Paper
PDF
67% (3)
Class 5 EM Model Question Paper
9 pages
Class 6 PDF
PDF
No ratings yet
Class 6 PDF
27 pages
Class 7 - Mathematics - Yearly - Reena Krishnakumar - Reena Krishnakumar
PDF
No ratings yet
Class 7 - Mathematics - Yearly - Reena Krishnakumar - Reena Krishnakumar
6 pages
CBSE Class 9 Science Chapter 3 Atoms Amd Molecules Notes
PDF
No ratings yet
CBSE Class 9 Science Chapter 3 Atoms Amd Molecules Notes
4 pages
MOTION
PDF
No ratings yet
MOTION
36 pages
Selina Solution Concise Maths Class 6 Chapter 11
PDF
No ratings yet
Selina Solution Concise Maths Class 6 Chapter 11
24 pages
Number System Model Paper For Class Ix
PDF
No ratings yet
Number System Model Paper For Class Ix
3 pages
3A - Arithmetic Progression Q
PDF
No ratings yet
3A - Arithmetic Progression Q
1 page
Playing With Numbers
PDF
No ratings yet
Playing With Numbers
1 page
7th Maths-Deciumals and Fractrions
PDF
No ratings yet
7th Maths-Deciumals and Fractrions
44 pages
Introduction To Databases: Grade 7
PDF
No ratings yet
Introduction To Databases: Grade 7
12 pages
Unit 4 Learning Guide
PDF
No ratings yet
Unit 4 Learning Guide
27 pages
Ch1 - Motion
PDF
No ratings yet
Ch1 - Motion
44 pages
Maths Grade 6 (Iv)
PDF
No ratings yet
Maths Grade 6 (Iv)
4 pages
Understanding Quadrilaterals
PDF
No ratings yet
Understanding Quadrilaterals
68 pages
Computer Programs Class 12 Computer Science 2
PDF
No ratings yet
Computer Programs Class 12 Computer Science 2
58 pages
978-0-00-753774-7 Pupil Book 2.1
PDF
No ratings yet
978-0-00-753774-7 Pupil Book 2.1
27 pages
03 Gravitation
PDF
No ratings yet
03 Gravitation
16 pages
Hindi Grammar SA2 Grade 4
PDF
No ratings yet
Hindi Grammar SA2 Grade 4
20 pages
LR 1 - Numbers & Letter Series
PDF
No ratings yet
LR 1 - Numbers & Letter Series
10 pages
Money Crunch Worksheet
PDF
No ratings yet
Money Crunch Worksheet
31 pages
Exponents Revision Class 8
PDF
No ratings yet
Exponents Revision Class 8
2 pages
Indian Mathematicians and Their Contributions: Ramanujan
PDF
No ratings yet
Indian Mathematicians and Their Contributions: Ramanujan
4 pages
Occupation-Its Importance (4th)
PDF
No ratings yet
Occupation-Its Importance (4th)
3 pages
Class 9 Maths Circles
PDF
No ratings yet
Class 9 Maths Circles
11 pages
Grade 8 Exam Questions
PDF
No ratings yet
Grade 8 Exam Questions
10 pages
1 995 Mathematics Olympiad Lecture Notes - Review of Logarithms - Greg Gamble - Logs
PDF
100% (1)
1 995 Mathematics Olympiad Lecture Notes - Review of Logarithms - Greg Gamble - Logs
5 pages
Class I Holiday H.W. 2024-25 (1) - 1
PDF
No ratings yet
Class I Holiday H.W. 2024-25 (1) - 1
11 pages
Squares & Square Roots
PDF
No ratings yet
Squares & Square Roots
16 pages
Indices
PDF
0% (1)
Indices
33 pages
Pre 10
PDF
No ratings yet
Pre 10
9 pages
INDIAN INTERNATIONAL NUMBER SYSTEM-Notes PDF
PDF
No ratings yet
INDIAN INTERNATIONAL NUMBER SYSTEM-Notes PDF
10 pages
Poddar Brio International School (Cbse) : Periodic Test-3
PDF
100% (2)
Poddar Brio International School (Cbse) : Periodic Test-3
3 pages
Adding Decimals
PDF
No ratings yet
Adding Decimals
37 pages
Grade-09 Mathematics Chapter01 Number-Systems
PDF
No ratings yet
Grade-09 Mathematics Chapter01 Number-Systems
12 pages
NCERT Solutions For Cbse Class 9 Maths Chapter 1 Number System PDF
PDF
No ratings yet
NCERT Solutions For Cbse Class 9 Maths Chapter 1 Number System PDF
22 pages
Matter in Our Surrounding
PDF
No ratings yet
Matter in Our Surrounding
62 pages
Statistic (Summation Notation) PDF
PDF
100% (1)
Statistic (Summation Notation) PDF
9 pages
Class 8 Science Notes Chapter 3 Synthetic Fibers and Plastics
PDF
No ratings yet
Class 8 Science Notes Chapter 3 Synthetic Fibers and Plastics
28 pages
Squares and Square Roots Assignment 12
PDF
No ratings yet
Squares and Square Roots Assignment 12
3 pages
CBSE Class 6 Maths Practice Worksheets
PDF
No ratings yet
CBSE Class 6 Maths Practice Worksheets
3 pages
Looping in QBASIC
PDF
No ratings yet
Looping in QBASIC
11 pages
Teacher's Orientation
PDF
No ratings yet
Teacher's Orientation
21 pages
Environmental Risk Factors of Type 2 Diabetes - An Exposome Approach
PDF
No ratings yet
Environmental Risk Factors of Type 2 Diabetes - An Exposome Approach
12 pages
Grid References Booklet
PDF
100% (2)
Grid References Booklet
10 pages