Download presentation
Presentation is loading. Please wait.
Published byRonald Hart Modified over 9 years ago
1
Fac of Ene & Surveying U.S.Q.1 E0001 Computers in Engineering DO.... LOOP
2
Fac of Ene & Surveying U.S.Q.2 Readings l Schneider Chapter 6 sections 6.1 and 6.2 - problems as required l Schneider p 84 on TUTORIALS l WILL CONTINUE BUT NOT COMPULSORY
3
Fac of Ene & Surveying U.S.Q.3 This Lecture: l two types POST TEST DO.. LOOPS l INKEY$ statement
4
Fac of Ene & Surveying U.S.Q.4 DO LOOP l loops repeat a set of statements - used when an UNKNOWN number if iterations is required l DO indicates the top of the loop LOOP indicates the end of the loop l DO without a LOOP and visa versa will give a run time error. Same rules for NESTED loops apply l four ways to write a DO LOOP –pre & post test; WHILE & UNTIL
5
Fac of Ene & Surveying U.S.Q.5 conditions l conditions use RELATIONAL and LOGIC operators l evaluated to TRUE or FALSE l if conditions are not met, the control passes to statement immediately after the LOOP
6
Fac of Ene & Surveying U.S.Q.6 Program l write a program to read the product code, number on hand and number on order for an unknown number of products
7
Fac of Ene & Surveying U.S.Q.7 pseudocode data to read ? no read code, # on hand, # on order print ‘end’ end
8
Fac of Ene & Surveying U.S.Q.8 code DO WHILE code$ <> “eof” READ code$, onhand, onorder PRINT code$, on hand, onorder LOOP PRINT “end of report” DATA glue,5,7,tape,1,20,book1,2,30, paper, 4,3,eof,0,0
9
Fac of Ene & Surveying U.S.Q.9 Pre - test Loop l DO WHILE condition statement (s) LOOP l DO UNTIL condition statement(s) LOOP l condition tested before statements are executed l statements executed if condition true
10
Fac of Ene & Surveying U.S.Q.10 Post - test Loops l DO statement(s) LOOP WHILE condition l DO statement(s) LOOP UNTIL condition l in post-test loops statements are executed at least once
11
Fac of Ene & Surveying U.S.Q.11 Post-test WHILE loop flowchart execute statements in loop condition True False DO statements LOOP WHILE condition
12
Fac of Ene & Surveying U.S.Q.12 Post-test UNTIL loop flowchart execute statements in loop condition True False DO statements LOOP UNTIL condition
13
Fac of Ene & Surveying U.S.Q.13 INKEY$ l Reads a character from the keyboard. l INKEY$ returns a null string if there is no character to return. l Example: PRINT "Press Esc to exit..." DO LOOP UNTIL INKEY$ = CHR$(27) '27 is the ASCII code for Esc.
14
Fac of Ene & Surveying U.S.Q.14 beware!! DO INPUT choice$ SELECT CASE choice$ CASE circle:..... CASE square:... CASE ELSE :..... END SELECT LOOP INKEY$<>““‘null string INKEY$ executes quickly! Unless you are pressing a key at the exact instant the statement executes it will return a null string and hence loop
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.