e0001 computers in engineering
Download
Skip this Video
Download Presentation
E0001 Computers in Engineering

Loading in 2 Seconds...

play fullscreen
1 / 16

E0001 Computers in Engineering - PowerPoint PPT Presentation


  • 95 Views
  • Uploaded on

E0001 Computers in Engineering. DO .... LOOP. Readings. Schneider Chapter 6 sections 6.1 and 6.2 - problems as required Schneider p 84 on This Lecture: two types PRETEST DO.. LOOPS. Assignment Documentation. Flowcharts OR pseudocode for main routine and ALL subs and functions

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'E0001 Computers in Engineering' - trixie


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
readings
Readings
  • Schneider Chapter 6 sections 6.1 and 6.2 - problems as required
  • Schneider p 84 on

This Lecture:

  • two types PRETEST DO.. LOOPS
assignment documentation
Assignment Documentation
  • Flowcharts OR pseudocode for main routine and ALL subs and functions
  • overviews for main, subs and functions
    • written paragraph/s stating what it does, how it does it, variables used from and returned to main routine
  • code with comments
  • screen dumps - ask in tut
  • write protected disk with code
  • flowcharts etc printed one staple in corner in folder
do loop
DO LOOP
  • loops repeat a set of statements - used when an UNKNOWN number if iterations is required
  • DO indicates the top of the loop

LOOP indicates the end of the loop

  • DO without a LOOP and visa versa will give a run time error. Same rules for NESTED loops apply
  • four ways to write a DO LOOP
    • pre & post test; WHILE & UNTIL
pre test loop condition tested before statements are executed
Pre - test Loop condition tested before statements are executed

DO WHILE condition

statement (s)

LOOP

  • statements executed if condition true

DO UNTIL condition

statement(s)

LOOP

  • statements executed if condition false or UNTIL condition true
pretest while loop flowchart
execute

statements in

loop

true

condition

false

Pretest WHILE loop flowchart

DO WHILE condition

loop statements

LOOP

pretest until loop flowchart
Pretest UNTIL loop flowchart

execute

statements in

loop

false

condition

true

DO UNTIL condition

loop statements

LOOP

conditions
conditions
  • conditions use RELATIONAL and LOGIC operators
  • evaluated to TRUE or FALSE
  • if conditions are not met, the control passes to statement immediately after the LOOP
  • control value must be able to be changed in loop else infinite loop
example
sum =0

i=0

DO WHILE sum<1000

i = i+1

sum = sum +i

LOOP

PRINT “sum of first”;i ;”integers is”;sum

‘initalise sum to zero

‘as long as sum <1000

‘set i to next integer and add to sum

‘repeat

Example
write a corresponding do until loop
sum =0

i=0

DO WHILE sum<1000

i = i+1

sum = sum +i

LOOP

PRINT “sum of first”;i ;”integers is”;sum

sum =0

i=0

DO UNTIL ???????

i = i+1

sum = sum +i

LOOP

PRINT “sum of first”;i ;”integers is”;sum

Write a corresponding DO UNTIL loop
similar loop using until pretest equivalent condition
sum =0

i=0

DO WHILE sum<1000

i = i+1

sum = sum +i

LOOP

PRINT “sum of first”;i ;”integers is”;sum

sum =0

i=0

DO UNTIL sum>1000

i = i+1

sum = sum +i

LOOP

PRINT “sum of first”;i ;”integers is”;sum

similar loop using UNTIL pretestequivalent condition
uses for do loops
uses for DO LOOPS
  • to read or process an unknown number of data
  • used with ‘flags’
  • re-run programs until user choice to finish
examples
examples

DO WHILE choice$<>“n”

sum =0

i=0

DO WHILE sum<1000

i = i+1

sum = sum +i

LOOP

PRINT “sum of first”;i ;”integers is”;sum

INPUT “continue?y/n”; choice$

LOOP

original program

nested loop

using flags flag 1
using flags (flag = 1)

DO LOOP WHILE flag = 1 flag = 0

FOR i = 1 TO 19 bar(i) = (bar(i - 1) + bar(i) + bar(i + 1)) / 3 actualtoler = ABS(oldbar(i) - bar(i)) IF actualtoler >= tol THEN flag = 1 PRINT i, bar(i), oldbar(i), actualtoler oldbar(i) = bar(i)

NEXT

LOOP

process data used with files and eof or eod markers
process data; used with files and eof or eod markers

eod - end of data marker

in this case 999

sum =0: n=0

READ v

DO WHILE v <> 999

sum = sum +v

n = n+1

READ v

LOOP

average = sum/n

DATA 21,22,23,25,4,55,67,999

eod with string data and multiple reads
eod with string data and multiple reads

READ name$, address$, age

DO WHILE name$ <> “eod”

PRINT name$, address$,age

total = total +age

n = n+1

READ name$, address$, age

LOOP

PRINT “average age”;total/n

DATA harry, 10 smith, 24, eod, 0, 0

ad