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)
38 views
Chapter4QBasic ProgrammingStatements
Uploaded by
vaishnavimadan
AI-enhanced title
Copyright
© © All Rights Reserved
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)
38 views
Chapter4QBasic ProgrammingStatements
Uploaded by
vaishnavimadan
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Chapter4QBasic-ProgrammingStatements For Later
Carousel Previous
Carousel Next
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
Lines and Angles Icse Class 7 Maths by Rs Agarwal
PDF
No ratings yet
Lines and Angles Icse Class 7 Maths by Rs Agarwal
15 pages
9 Chapter-8
PDF
100% (1)
9 Chapter-8
16 pages
DPT Arithmetic Progression - 01
PDF
No ratings yet
DPT Arithmetic Progression - 01
3 pages
Linear Equations in One Variable r1
PDF
No ratings yet
Linear Equations in One Variable r1
21 pages
Airthmetic Progression
PDF
No ratings yet
Airthmetic Progression
15 pages
Class 7th
PDF
No ratings yet
Class 7th
24 pages
NCERT Exemplar Class 7 Maths Integers
PDF
No ratings yet
NCERT Exemplar Class 7 Maths Integers
661 pages
Squares and Square Roots
PDF
No ratings yet
Squares and Square Roots
41 pages
Maths PracticeBook23 C7
PDF
No ratings yet
Maths PracticeBook23 C7
123 pages
Diversity in Living Organisms
PDF
No ratings yet
Diversity in Living Organisms
7 pages
Introduction To Graphs Handout & Worksheet
PDF
No ratings yet
Introduction To Graphs Handout & Worksheet
6 pages
Selina Concise Mathematics Class 7 ICSE Solutions For Chapter 11 - Fundamental Concepts
PDF
No ratings yet
Selina Concise Mathematics Class 7 ICSE Solutions For Chapter 11 - Fundamental Concepts
146 pages
NCERT Solutions For Class 11 Physics Chapter 2 Units and Measurement
PDF
No ratings yet
NCERT Solutions For Class 11 Physics Chapter 2 Units and Measurement
21 pages
Assignment Real Numbers Class X: Answers
PDF
No ratings yet
Assignment Real Numbers Class X: Answers
1 page
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
Class 10 Maths Notes Chapter 1 Studyguide360
PDF
No ratings yet
Class 10 Maths Notes Chapter 1 Studyguide360
13 pages
Basic Maths 0
PDF
No ratings yet
Basic Maths 0
21 pages
Linear Equations in Two Variables
PDF
No ratings yet
Linear Equations in Two Variables
12 pages
Class 7 CH 6 Physical and Chemical Changes
PDF
0% (1)
Class 7 CH 6 Physical and Chemical Changes
6 pages
INDIAN INTERNATIONAL NUMBER SYSTEM-Notes PDF
PDF
No ratings yet
INDIAN INTERNATIONAL NUMBER SYSTEM-Notes PDF
10 pages
Class 8 Maths Sitamarhi Talent Search
PDF
No ratings yet
Class 8 Maths Sitamarhi Talent Search
14 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
Money Crunch Worksheet
PDF
No ratings yet
Money Crunch Worksheet
31 pages
Scholarship Test For Class 5th-4
PDF
100% (1)
Scholarship Test For Class 5th-4
8 pages
NCERT - Class7 Physical and Chemical Changes
PDF
No ratings yet
NCERT - Class7 Physical and Chemical Changes
6 pages
11. Probability X
PDF
No ratings yet
11. Probability X
18 pages
NCERT Solutions For Class 6 Maths Exercise 7.1 Chapter 7 Fraction - Free PDF
PDF
No ratings yet
NCERT Solutions For Class 6 Maths Exercise 7.1 Chapter 7 Fraction - Free PDF
1 page
NCERT Solutions Class 11 Maths Chapter 1 Sets
PDF
No ratings yet
NCERT Solutions Class 11 Maths Chapter 1 Sets
34 pages
Crop Production and Managment (Allen PDF
PDF
No ratings yet
Crop Production and Managment (Allen PDF
22 pages
8 Maths PPT (Visualising Solid Shapes)
PDF
No ratings yet
8 Maths PPT (Visualising Solid Shapes)
21 pages
Bodmas-20 10 20
PDF
No ratings yet
Bodmas-20 10 20
4 pages
Angles Worksheets Grade 5 - Worksheet 4.2
PDF
100% (1)
Angles Worksheets Grade 5 - Worksheet 4.2
4 pages
RS Aggarwal Solution Class 10 Maths Chapter 1 Real Number Exercise 1E
PDF
No ratings yet
RS Aggarwal Solution Class 10 Maths Chapter 1 Real Number Exercise 1E
6 pages
Natural Vegetation and Wildlife - Notes
PDF
No ratings yet
Natural Vegetation and Wildlife - Notes
3 pages
Heros Convent HR - Sec.School First Term Examination Class - 4 Maths M.M.80
PDF
No ratings yet
Heros Convent HR - Sec.School First Term Examination Class - 4 Maths M.M.80
3 pages
Class Ix - 11 Gravitation Worksheet
PDF
No ratings yet
Class Ix - 11 Gravitation Worksheet
2 pages
Maths Notes Class 8
PDF
No ratings yet
Maths Notes Class 8
24 pages
7th Maths-Deciumals and Fractrions
PDF
No ratings yet
7th Maths-Deciumals and Fractrions
44 pages
7th Physics DLP Study Package Final
PDF
No ratings yet
7th Physics DLP Study Package Final
92 pages
8th Square and Square Root 8th Cube
PDF
No ratings yet
8th Square and Square Root 8th Cube
3 pages
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
Probability Questions Cbse Class 10
PDF
No ratings yet
Probability Questions Cbse Class 10
15 pages
Cbse Sample Paper For Class 8 Mathematics Sa 2
PDF
No ratings yet
Cbse Sample Paper For Class 8 Mathematics Sa 2
4 pages
The Frog and The Nightingale: - Vikram Seth
PDF
No ratings yet
The Frog and The Nightingale: - Vikram Seth
10 pages
Class VIII - Split-Up Syllabus, 2023-24
PDF
No ratings yet
Class VIII - Split-Up Syllabus, 2023-24
29 pages
M7.7 BK v4.0 20190110 The Triangle and Its Properties
PDF
No ratings yet
M7.7 BK v4.0 20190110 The Triangle and Its Properties
89 pages
Class 3
PDF
No ratings yet
Class 3
11 pages
Class 6 PDF
PDF
No ratings yet
Class 6 PDF
27 pages
1.3 Surds, Indices, Log
PDF
No ratings yet
1.3 Surds, Indices, Log
18 pages
Mat Watermark PDF
PDF
No ratings yet
Mat Watermark PDF
246 pages
Class 7 - Mathematics - Yearly - Reena Krishnakumar - Reena Krishnakumar
PDF
No ratings yet
Class 7 - Mathematics - Yearly - Reena Krishnakumar - Reena Krishnakumar
6 pages
Itho Class 7
PDF
No ratings yet
Itho Class 7
1 page
Hindi Grammar SA2 Grade 4
PDF
No ratings yet
Hindi Grammar SA2 Grade 4
20 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
B8-Conservation of Plants and Animals
PDF
No ratings yet
B8-Conservation of Plants and Animals
68 pages
Looping in QBASIC
PDF
No ratings yet
Looping in QBASIC
11 pages
If, If Then, Nested If Selection Statements & Loops
PDF
No ratings yet
If, If Then, Nested If Selection Statements & Loops
52 pages
CSM 157 PROGRAMMING-Week5
PDF
No ratings yet
CSM 157 PROGRAMMING-Week5
17 pages
Class-8 Ict Ppt Q-basic
PDF
No ratings yet
Class-8 Ict Ppt Q-basic
20 pages
LOOP
PDF
No ratings yet
LOOP
6 pages
Class 6 Chapter 6 Introduction To HTML
PDF
80% (5)
Class 6 Chapter 6 Introduction To HTML
6 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