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)
101 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
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)
101 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
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
702B B.P.S. VII S.A. I II Maths Chapterwise 5 Printable Worksheets With Solution 2014 15
PDF
100% (1)
702B B.P.S. VII S.A. I II Maths Chapterwise 5 Printable Worksheets With Solution 2014 15
160 pages
Assignment Real Numbers Class X: Answers
PDF
No ratings yet
Assignment Real Numbers Class X: Answers
1 page
B8-Conservation of Plants and Animals
PDF
No ratings yet
B8-Conservation of Plants and Animals
68 pages
Class VIII - Split-Up Syllabus, 2023-24
PDF
No ratings yet
Class VIII - Split-Up Syllabus, 2023-24
29 pages
Diversity in Living Organisms
PDF
No ratings yet
Diversity in Living Organisms
7 pages
03 Gravitation
PDF
No ratings yet
03 Gravitation
16 pages
Notes - Introduction To Euclid's Geometry
PDF
No ratings yet
Notes - Introduction To Euclid's Geometry
9 pages
CL-9, Notes On Number System
PDF
No ratings yet
CL-9, Notes On Number System
5 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
9 Chapter-8
PDF
100% (1)
9 Chapter-8
16 pages
CBSE G+09 Coordinate+Geometry Notes
PDF
No ratings yet
CBSE G+09 Coordinate+Geometry Notes
5 pages
Class 8 Science Ncert Notes Chapter 2 - Micro - Organisms - Friend - or - Foe
PDF
No ratings yet
Class 8 Science Ncert Notes Chapter 2 - Micro - Organisms - Friend - or - Foe
51 pages
Class 8 Maths Sitamarhi Talent Search
PDF
No ratings yet
Class 8 Maths Sitamarhi Talent Search
14 pages
ZRK LIST OF BOOKS - 2023-24 For Website - Remove
PDF
No ratings yet
ZRK LIST OF BOOKS - 2023-24 For Website - Remove
16 pages
Class 3
PDF
No ratings yet
Class 3
11 pages
Summer Holidays' Homework (2024-25) Class: IX: We Wish You All A Fun-Filled and Safe Summer Vacation!
PDF
No ratings yet
Summer Holidays' Homework (2024-25) Class: IX: We Wish You All A Fun-Filled and Safe Summer Vacation!
15 pages
Chapter - 3 Structure of Matter: 25/04/2019 Grade: Vii Enable
PDF
No ratings yet
Chapter - 3 Structure of Matter: 25/04/2019 Grade: Vii Enable
3 pages
Mensuration Formulas PDF For All 2D, 3D Shapes in Maths
PDF
No ratings yet
Mensuration Formulas PDF For All 2D, 3D Shapes in Maths
16 pages
Class - VIII: Combustion and Flame
PDF
No ratings yet
Class - VIII: Combustion and Flame
27 pages
IISR Class VII Maths Worksheet
PDF
No ratings yet
IISR Class VII Maths Worksheet
14 pages
Ratio & Proportion
PDF
No ratings yet
Ratio & Proportion
2 pages
Class 8 Square and Square Roots
PDF
No ratings yet
Class 8 Square and Square Roots
24 pages
Grade 09 Mathematics Chapter04 Linear Equations in Two Variables
PDF
No ratings yet
Grade 09 Mathematics Chapter04 Linear Equations in Two Variables
5 pages
Improvement in Food Resources Class 9 Notes
PDF
No ratings yet
Improvement in Food Resources Class 9 Notes
8 pages
Matter in Our Surrounding
PDF
No ratings yet
Matter in Our Surrounding
62 pages
CBSE Class 8 Mathematics Practice Worksheet
PDF
No ratings yet
CBSE Class 8 Mathematics Practice Worksheet
2 pages
1003B B.P.S. X S.A. I Maths Chapterwise 5 Printable Worksheets With Solution 2014 15
PDF
No ratings yet
1003B B.P.S. X S.A. I Maths Chapterwise 5 Printable Worksheets With Solution 2014 15
140 pages
Wastewater Story
PDF
No ratings yet
Wastewater Story
14 pages
Introduction To Graphs Handout & Worksheet
PDF
No ratings yet
Introduction To Graphs Handout & Worksheet
6 pages
Class 9 Maths Circles
PDF
No ratings yet
Class 9 Maths Circles
11 pages
Maths PracticeBook23 C7
PDF
No ratings yet
Maths PracticeBook23 C7
123 pages
Squares and Square Roots
PDF
No ratings yet
Squares and Square Roots
41 pages
Square and Square Roots: Class VIII. BPS Maths Worksheet
PDF
No ratings yet
Square and Square Roots: Class VIII. BPS Maths Worksheet
2 pages
Class 5 Maths Inner Term 1
PDF
0% (1)
Class 5 Maths Inner Term 1
76 pages
Disha Class10 10-In-1 Mathematics Arithmetic Progressions
PDF
No ratings yet
Disha Class10 10-In-1 Mathematics Arithmetic Progressions
44 pages
Maths Class Viii Practice Test 04 Algebraic Expressions and Identities Answers
PDF
No ratings yet
Maths Class Viii Practice Test 04 Algebraic Expressions and Identities Answers
3 pages
Science Class 7 Notes
PDF
No ratings yet
Science Class 7 Notes
11 pages
Class 7 - Mathematics - Yearly - Reena Krishnakumar - Reena Krishnakumar
PDF
No ratings yet
Class 7 - Mathematics - Yearly - Reena Krishnakumar - Reena Krishnakumar
6 pages
Rational Numbers Important Questions For Class 8: Short Answer Type Questions
PDF
No ratings yet
Rational Numbers Important Questions For Class 8: Short Answer Type Questions
2 pages
Exp SC 7 - Chapter 14
PDF
No ratings yet
Exp SC 7 - Chapter 14
13 pages
FLN JGTL Maths Base Line em
PDF
No ratings yet
FLN JGTL Maths Base Line em
4 pages
Linear Equations in Two Variables
PDF
No ratings yet
Linear Equations in Two Variables
12 pages
Class 8 - Maths - CH - 7 - CUBES AND CUBE ROOTS
PDF
No ratings yet
Class 8 - Maths - CH - 7 - CUBES AND CUBE ROOTS
14 pages
WorkSheet Knowing Our Numbers
PDF
No ratings yet
WorkSheet Knowing Our Numbers
6 pages
IFSE Maths Syllabus
PDF
No ratings yet
IFSE Maths Syllabus
1 page
Class 7 CH 6 Physical and Chemical Changes
PDF
0% (1)
Class 7 CH 6 Physical and Chemical Changes
6 pages
Occupation-Its Importance (4th)
PDF
No ratings yet
Occupation-Its Importance (4th)
3 pages
Class IX Biology Unit 2 df47120b 457b 4a7d b912 f199fc714805
PDF
No ratings yet
Class IX Biology Unit 2 df47120b 457b 4a7d b912 f199fc714805
88 pages
Maths Grade 6 (Iv)
PDF
No ratings yet
Maths Grade 6 (Iv)
4 pages
INDIAN INTERNATIONAL NUMBER SYSTEM-Notes PDF
PDF
No ratings yet
INDIAN INTERNATIONAL NUMBER SYSTEM-Notes PDF
10 pages
Squares & Square Roots
PDF
No ratings yet
Squares & Square Roots
16 pages
Hindi Grammar SA2 Grade 4
PDF
No ratings yet
Hindi Grammar SA2 Grade 4
20 pages
7th Maths-Deciumals and Fractrions
PDF
No ratings yet
7th Maths-Deciumals and Fractrions
44 pages
ASSET - English Olympiad Practice Papers For Class 7
PDF
No ratings yet
ASSET - English Olympiad Practice Papers For Class 7
1 page
Class 8th Chapter 16 Assignment
PDF
No ratings yet
Class 8th Chapter 16 Assignment
4 pages
NCERT Solutions Class 11 Maths Chapter 1 Sets
PDF
No ratings yet
NCERT Solutions Class 11 Maths Chapter 1 Sets
34 pages
Number System Model Paper For Class Ix
PDF
No ratings yet
Number System Model Paper For Class Ix
3 pages
Looping in QBASIC
PDF
No ratings yet
Looping in QBASIC
11 pages
CSM 157 PROGRAMMING-Week5
PDF
No ratings yet
CSM 157 PROGRAMMING-Week5
17 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