Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 4 REPETITIVE EXECUTION. Counter-Controlled DO Loops DO Number = 1, 9 PRINT *, Number, Number**2 END DO DO Number = 9, 1, -1 PRINT *, Number, Number**2.

Similar presentations


Presentation on theme: "CHAPTER 4 REPETITIVE EXECUTION. Counter-Controlled DO Loops DO Number = 1, 9 PRINT *, Number, Number**2 END DO DO Number = 9, 1, -1 PRINT *, Number, Number**2."— Presentation transcript:

1 CHAPTER 4 REPETITIVE EXECUTION

2 Counter-Controlled DO Loops DO Number = 1, 9 PRINT *, Number, Number**2 END DO DO Number = 9, 1, -1 PRINT *, Number, Number**2 END DO

3 Example: Summation INTEGER :: Number, I, Sum READ *, Number DO I = 1, Number Sum = Sum + I END DO

4 Example: A Multiplication Table DO M = 1, Last_M DO N = 1, Last_N Product = M * N PRINT *, M, “ “, N, “ “, Product END DO

5 DEPRECIATION ( 折舊 ) TABLES Depreciation is the decrease in value over time of some asset due to wear and tear, declining price, and so on. For example, suppose that a company purchases a new robot for $20,000 that will be used on its assembly line for 5 years. After that time, called the useful life of the robot, it can be sold at an estimated price of $5,000, which is the robot ’ s salvage value. Thus, the value of the robot will have depreciated $15,000 over the 5-year period. A program is needed to calculate depreciation tables that display the depreciation in each year of the item ’ s useful life.

6 A Robotic Arm

7 DEPRECIATION TABLES Method = 1 (The straight-line method) Depreciation = Amount / UsefulLife Method = 2 (The sum-of-the-years ’ - digits method) Sum = 1 + 2 + … + UsefulLife Depreciation = (UsefulLife – Year + 1) * Amount / Sum

8 General DO Loops: DO-EXIT Construct DO IF (Sum > Limit) EXIT Number = Number + 1 Sum = Sum + Number END DO

9 Pretest Loop: “ test-at-the-top ” loop DO IF (logical-expression) EXIT statement-sequence END DO

10 Posttest Loop: “ test-at-the-bottom ” loop DO statement-sequence IF (logical-expression) EXIT END DO

11 DO Loop: Other Type “ Test-in-the-middle ” loop Query-controlled input loops Query ( 疑問 ); Control ( 控制 )

12 CYCLE Statement DO (p. 214, Textbook) READ *, Celsius IF (Celsius < 0.0) PRINT *, “ ** Temperature must be 0 or above ** ” CYCLE END IF (p. 214, Textbook) READ * Response IF (Response == “ N ” ) EXIT END DO

13 Named DO Constructs Outer: DO M = 1, Last_M Inner: DO N = 1, Last_N Product = M * N PRINT *, M, “ “, N, “ “, Product END DO Inner END DO Outer

14 Mean Time to Failure ( 故障平均時間 ) One important statistic ( 統計 ) used in measuring the reliability ( 可靠度 ) of a component in a circuit is the mean time to failure, which can be used to predict the circuit ’ s life time. This is especially important in situation in which repair is difficult or even impossible, such as a computer circuit in a space satellite.

15 Mean Time to Failure Suppose that NASA (National Aeronautics and Space Administration) has awarded an engineering laboratory a contract ( 合約 ) to evaluate the reliability of particular component for a future space probe ( 探測 ) to Mars ( 火星 ). As part of this evaluation, an engineer at this laboratory has test of these circuits and recorded the time at which each failed; now she would like a program to process this data and determine the mean time to failure.

16 Space Probe ( 太空 探測 )


Download ppt "CHAPTER 4 REPETITIVE EXECUTION. Counter-Controlled DO Loops DO Number = 1, 9 PRINT *, Number, Number**2 END DO DO Number = 9, 1, -1 PRINT *, Number, Number**2."

Similar presentations


Ads by Google