{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

mud11 - Lecture C11 FOR WHILE and General Loops Response...

This preview shows pages 1–3. Sign up to view the full content.

Lecture C11: FOR, WHILE and General Loops Response to 'Muddiest Part of the Lecture Cards' (45 respondents) 1) General comments on lecture / class. (2 students) Class is too early : Sorry not much I can do about that... more than maybe agree that Monday 9am is very early indeed. Can you post your examples online? I will put all my in-class-examples in a .zip file and distribute to class. Where can we find lots of practice problems? As mentioned in earlier mud response, take a look in the Feldman Ada book or any other Ada book, there are lots and lots of examples to work through, and many of them alos have solutions on the CD or within the book. 2) What is the difference between a Definite and Indefinite while loop? (1 students) While loops are generally used for indefinite iteration i.e. the number of times the loop has to execute has not been determined. A For loop is used for definite iteration i.e. the number of times the loop has been executed is predetermined. You can replace a For loop with a while loop, but the substitution is prone to error because the tests. Algorithm to convert a For loop into a While loop: 1. Create a loop variable (in a for loop, the loop variable need not be declared). 2. Initialize the loop variable to the lower_bound of the for loop prior to entering the loop. 3. If lower_bound <= upper bound and ‘ for I in lower_bound .. upper_bound loop a. The For loop is replaced by ‘While (loop_variable <= upper_bound) loop’ b. Increment loop_variable by 1 c. Replace every occurrence of the For Loop counter by loop_variable d. Rest of program body 4. If (lower_bound > upper_bound) and ‘ for I in reverse lower_bound .. upper_bound loop

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

View Full Document
a. The For loop is replaced by ‘While (loop_variable >= upper_bound) loop’ b. Decrement loop_variable by 1 c. Replace every occurrence of the For Loop counter by loop_variable d. Rest of program body -- for for_loop_counter in lower_bound .. upper_bound for I in 1 .. N loop --loop body end loop ; -- replace with while Loop_Variable <= Upper_Bound loop Loop_Variable := Loop_Variable + 1 ; -- loop body end loop ; 3) Sentinel and Flag loops? (4 students) What is their syntax? Are they special kinds of while loops? When is it good to use them? What real-life cases would one use sentinel loops? How is using a flag more effective than other techniques?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}