Lesson+3

//**Repetitive structures: Infinite and Conditional Loops **// Imagine an assignment which asks you to output to screen all numbers from 1 to 1000. You would have to put 1 put 2 put 3... one hundred times. Loops are a means through which a program can repeat commands using a few lines so you won't have to using many lines. There are, in Turing, 3 kinds of loops:
 * LESSON 3 **

1) Infinite; 2) Conditional 3) Counted

Infinite loops have no exit condition and therefore continue forever. Try this:

**loop**
 * put "Computer"**
 * end loop**

Notice that the loop statement is accompanied by an end loop statement. The syntax of a repetitive structure demands this.

Conditional loops have the same format as an infinite loop. The difference is that they end after a certain specified condition is met during program execution. This condition is specified using a exit when statement. Try this:
 * var answer: string **
 * put "How many evangelists wrote the gospels? " **
 * loop **
 *  get answer **
 *  exit when answer = "4" or answer = "four" **
 *  put "Sorry, try again" **
 * end loop **
 * put "Correct" **

Notice that the condition for a loop have been met: the loop command is accompanied by an end loop. The exit when statement specifies the conditionwhich must be met in order to end the loop; otherwise it continues infinitely.  **Task:**

1a) Write a program which will display a conversion table from miles to kilometres. Start with 5 miles and run to 100. The output should look something like this:

<span style="color: #000080; font-family: Arial,Helvetica,sans-serif; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">1b) Modify 1a) so it will allow the user to specify the starting and ending values. <span style="color: #000080; font-family: Arial,Helvetica,sans-serif; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">2) Write a program that a creates a dazzling and hypnotic kinetic pattern. The display must take place within a specified area of the screen and ends when any key is pressed. <span style="color: #000080; font-family: Arial,Helvetica,sans-serif; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">3a) Write a program that will draw a series of overlapping coloured circles from the centre of the screen to the lower-right hand corner until any key is pressed. <span style="color: #000080; font-family: Arial,Helvetica,sans-serif; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">3b) Modify a) so that the circles will bounce back from the edges of the screen at a random angle and continue to do so until a key is pressed. <span style="color: #000080; font-family: Arial,Helvetica,sans-serif; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">3c) Modify b) so that the circles will change colours and make a sound when they reach the edge of the screen. <span style="font-family: Arial,Helvetica,Geneva,Swiss,SunSans-Regular;">**getch stands for get character. hasch stands for has character. These two functions are useful when temporarily stopping and starting program execution.**
 * Miles || Kilometres ||
 * 5 || 8 ||
 * 6 || 9.6 ||
 * 7 || 11.2 ||