Class 7

# Class 7 - Click to edit Master subtitle style Flow Control...

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

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 12/4/09 Click to edit Master subtitle style Flow Control, continued Matthew Hashim 9/15/2009 11 MGMT 290D 12/4/09 Goals n Use the for and while statements to perform (other) statements more than once n Use Boolean variables and functions to control if and while statements n Use the wait() message to temporarily suspend program execution 22 MGMT 290D MGMT 290D 12/4/09 Introducing Repetition n Refer to flapWings() method from Figure 2-16 n Enhancement: use for loop to flap wings numTimes n Overview for implementing the enhancement ¨ Open the flapWings() method ¨ Adjust the duration values for the wing movements ¨ Drag loop control to the top of the method and drop ¨ Select numTimes for number of iterations ¨ Drag the doInOrder statement into the for statement 33 MGMT 290D MGMT 290D 12/4/09 Introducing Repetition (continued) 44 MGMT 290D MGMT 290D 12/4/09 Introducing Repetition (continued) 55 MGMT 290D MGMT 290D 12/4/09 Mechanics of the for Statement n Repeat statement execution a fixed number of times n Example: pass 3 to flapWings() for 3 flaps n Structure of the simple for statement ¨ for(int index = 0;index < limit;index++){ Statements } n The for statement is also known as a counting loop ¨ First statement in ( ) initializes the index ¨ Second statement in ( ) checks index against limit ¨ Third statement in ( ) increments the index 66 MGMT 290D MGMT 290D 12/4/09 Mechanics of the for Statement (continued) 77 MGMT 290D MGMT 290D 12/4/09 Mechanics of the for Statement (continued) n To test a for loop, trace the behavior with values ¨ Statements are executed while index < numTimes ¨ Example: send flapWings(3) to the dragon object n Simple version of for lets you modify limit value n Purpose of show complicated version button ¨ Change initial value of index and/or update to index ¨ Example: change update to index+=2 n Note: neither version of for allows you to count down 88 MGMT 290D MGMT 290D 12/4/09 Mechanics of the for Statement (continued) 99 MGMT 290D MGMT 290D 12/4/09 Mechanics of the for Statement (continued) 1010 MGMT 290D MGMT 290D 12/4/09 For practice n Build an Alice program where a coach says...
View Full Document

{[ snackBarMessage ]}

### Page1 / 36

Class 7 - Click to edit Master subtitle style Flow Control...

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

View Full Document
Ask a homework question - tutors are online