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)
89 views
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)
89 views
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
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
Answers of The Year 10 Mathematics Textbook
PDF
No ratings yet
Answers of The Year 10 Mathematics Textbook
138 pages
Sieve of Eratosthenes - Worksheet
PDF
No ratings yet
Sieve of Eratosthenes - Worksheet
1 page
Class 3
PDF
No ratings yet
Class 3
11 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
CL-9, Notes On Number System
PDF
No ratings yet
CL-9, Notes On Number System
5 pages
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
8 Maths PPT (Visualising Solid Shapes)
PDF
No ratings yet
8 Maths PPT (Visualising Solid Shapes)
21 pages
Diversity in Living Organisms
PDF
No ratings yet
Diversity in Living Organisms
7 pages
Squares and Square Roots
PDF
No ratings yet
Squares and Square Roots
41 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
Squares & Square Roots
PDF
No ratings yet
Squares & Square Roots
16 pages
Class 7 CH 6 Physical and Chemical Changes
PDF
0% (1)
Class 7 CH 6 Physical and Chemical Changes
6 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
Money Crunch Worksheet
PDF
No ratings yet
Money Crunch Worksheet
31 pages
Airthmetic Progression
PDF
No ratings yet
Airthmetic Progression
15 pages
Math 5 EM 2018-19 PDF
PDF
No ratings yet
Math 5 EM 2018-19 PDF
160 pages
DPT Arithmetic Progression - 01
PDF
No ratings yet
DPT Arithmetic Progression - 01
3 pages
7th Maths-Deciumals and Fractrions
PDF
No ratings yet
7th Maths-Deciumals and Fractrions
44 pages
Wastewater Story
PDF
No ratings yet
Wastewater Story
14 pages
History and Development of Mathematics in India
PDF
No ratings yet
History and Development of Mathematics in India
570 pages
Maths Grade 6 (Iv)
PDF
No ratings yet
Maths Grade 6 (Iv)
4 pages
9 Chapter-8
PDF
100% (1)
9 Chapter-8
16 pages
Assignment Real Numbers Class X: Answers
PDF
No ratings yet
Assignment Real Numbers Class X: Answers
1 page
CBSE Class 8 Mathematics Practice Worksheet
PDF
No ratings yet
CBSE Class 8 Mathematics Practice Worksheet
2 pages
Angles Worksheets Grade 5 - Worksheet 4.2
PDF
100% (2)
Angles Worksheets Grade 5 - Worksheet 4.2
4 pages
Chapter 7 Conservation of Plants and Animals
PDF
No ratings yet
Chapter 7 Conservation of Plants and Animals
4 pages
Herons Formula Class 9
PDF
No ratings yet
Herons Formula Class 9
4 pages
Science Class 7 Notes
PDF
No ratings yet
Science Class 7 Notes
11 pages
Number Place Value Planning
PDF
No ratings yet
Number Place Value Planning
3 pages
Multiplying 3 Digits by 2 Digits: Using The Vedic Method
PDF
No ratings yet
Multiplying 3 Digits by 2 Digits: Using The Vedic Method
12 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
Maths Class 9 Notes For Linear Equations in Two Variables PDF
PDF
No ratings yet
Maths Class 9 Notes For Linear Equations in Two Variables PDF
3 pages
8th Square and Square Root 8th Cube
PDF
No ratings yet
8th Square and Square Root 8th Cube
3 pages
Selina Solution Concise Maths Class 6 Chapter 11
PDF
No ratings yet
Selina Solution Concise Maths Class 6 Chapter 11
24 pages
Linear Equations in One Variable r1
PDF
No ratings yet
Linear Equations in One Variable r1
21 pages
Prime Factorization: by Jane Alam Jan
PDF
No ratings yet
Prime Factorization: by Jane Alam Jan
6 pages
Maths PracticeBook23 C7
PDF
No ratings yet
Maths PracticeBook23 C7
123 pages
Motion and Time
PDF
No ratings yet
Motion and Time
20 pages
Exponents Revision Class 8
PDF
No ratings yet
Exponents Revision Class 8
2 pages
Maths Notes For Class 10 Chapter 15 Probability
PDF
No ratings yet
Maths Notes For Class 10 Chapter 15 Probability
2 pages
Introduction To Graphs Handout & Worksheet
PDF
No ratings yet
Introduction To Graphs Handout & Worksheet
6 pages
CBSE Board Class 8 Maths Syllabus PDF
PDF
No ratings yet
CBSE Board Class 8 Maths Syllabus PDF
5 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
Squares and Square Roots Chapter Class Viii
PDF
100% (1)
Squares and Square Roots Chapter Class Viii
24 pages
Math IND Grade 7
PDF
No ratings yet
Math IND Grade 7
7 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
Computer Revision Class3
PDF
50% (2)
Computer Revision Class3
4 pages
Class 6 Computer
PDF
No ratings yet
Class 6 Computer
10 pages
Intro To Set Theory
PDF
No ratings yet
Intro To Set Theory
11 pages
Rationalizing The Denominators Worksheets
PDF
0% (1)
Rationalizing The Denominators Worksheets
1 page
Transpiration
PDF
No ratings yet
Transpiration
19 pages
7th Physics DLP Study Package Final
PDF
No ratings yet
7th Physics DLP Study Package Final
92 pages
Light Nsejs
PDF
No ratings yet
Light Nsejs
3 pages
Class 7 English Medium
PDF
0% (1)
Class 7 English Medium
12 pages
Chapter 3 Pointers
PDF
No ratings yet
Chapter 3 Pointers
46 pages
IISR Class VII Maths Worksheet
PDF
No ratings yet
IISR Class VII Maths Worksheet
14 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
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