note_07 - 116 Chapter 7 Design And Implementation Of Loops...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 116 Chapter 7 Design And Implementation Of Loops Repeat until : Repeat Body of Loop until Boolean Expression 1. Repeat Body Until Expression is True 2. No Compound statement used. 3. Always at least 1 pass through the loop. 117 Loop Categories Conditional Loops : 1) While & Repeat-until. 2) Loop continues or terminates based on a Boolean test. 3) Do not have to know in advance the specific number of repetitions. Counting Loop : 1) For statement. 2) Will set the loop to repeat a specific number of times. for control_variable := Initial to final do Begin Body of Loop Could be a single stmt with no End Begin-end. 118 For Execution : 3 steps automatically executed. 1) Initialization : Control variable is set to initial value. 2) Testing : Before each pass through the loop,Control variable is tested versus the final value. IF < = Final, make another pass through the loop. 3) Incrementation : The control variable is automatically incremented by 1 ; control returns to for statement for step 2 (testing). 119 FOR RULES : (1) The control variable must be declared within the module in which it is used. It must be ordinal ( Char, boolean or integer). (2) Control variable and initial and final values should not be altered within the loop. In Turbo Pascal modifying the control variable usually leads to unexpected results. Changes to initial & final values are ignored until loop is exited. (3) When loop is exited, the control variable retains the value it assumed on the last pass thru the loop. 120 Examples : (1) for I := 1 to 3 do writeln (Im looping); (2) for ID := 3024 to 3024 do writeln (ID) ; (3) for celcius := 30 to 40 do begin farenheit : = (9/5) * celcius + 32; writeln (farenheit :10:2) end; (4) for index := 3 to 2 do writeln (Hello); writeln (Goodbye); 121 Counting Down : for Count := 5 downto 1 do writeln ( Count :4, , Sqrt(Count) : 6:4); 5 2.2361 4 2.0000 3 1.7321 2 1.4142 1 1.0000 for I := 1 downto 5 do writeln ( Help Stuck in for Loop); 122 Eoln- Built-in Boolean function....
View Full Document

Page1 / 25

note_07 - 116 Chapter 7 Design And Implementation Of Loops...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online