# repetition: definite loops

Post on 22-Feb-2016

26 views

Category:

## Documents

Tags:

• #### certain number of times

Embed Size (px)

DESCRIPTION

Repetition: Definite Loops . Sec 8-13 Web Design. Objectives. The Student will: Understand loops and why they are used Understand definitive loops Know how to add loops to an Alice Program. Repetition. - PowerPoint PPT Presentation

TRANSCRIPT

Creating A New Instruction Method

bunny.hop

One solutionCreating the same instruction again and again is somewhat tedious and the code gets longer and longer.

Counted LoopA counted loop is an alternate way to write repetitive codeRepeats instructions a counted number of times

DemoCh07Lec1BunnyHopConcepts illustrated in this exampleThe loop instruction executes a definite number of times, specified by a countUsing a loop instruction saves time is convenient DemoCh07Lec1CarouselinfinityConcept illustrated in this example If Infinity times is selected for a loop, this means the loop will run until the program is shut down

More complicated loopsIt is also possible to place a loop statement within another loop statementThis is called nested loopsAn example of nested loops

The whole Ferris wheel will rotate clockwise, while the two inner wheels will rotate counterclockwise. The inner wheels should perform 2 revolutions for each outer loop revolution.DemoCh07Lec1FerrisWheelConcept illustrated in this example The inner loop runs completely each time the outer loop runs once. An outer loop that executes 2 times and an inner loop that executes 5 times will actually execute the inner loop 10 times.

12In an animation, opposite actions that occur simultaneously effectively cancel each other out in terms of the rendered action. To demonstrate, set the outer loop to 1 time and the inner loop to 2 times. The inner wheel will look as though it rotates only once. As another example, you would see the same kind of result if you try to turn a person's head left and right revolution at the same time.Using a function A loop count can be computed by calling a function that returns a number value. The loop instruction automatically rounds the returned value to the nearest whole number.Demo: Ch07Lec1LoopWithFunctionCallSummaryDefinitive Loops are used to repeat something a certain number of times.Use the Loop control structure add loops to Alice code.Loops can be nestedLoops can depend on function calls to set the number of times the code will be executed. AssignmentRead Chapter 7-1 LoopsDownload Chapter 7 sec 1 questionsDo one of the two the chapter 7-1 exercisesComplete the questions

Recommended