ch04 - Alice in Action with Java Chapter 4 Flow Control...

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

View Full Document Right Arrow Icon
Alice in Action with Java Chapter 4 Flow Control
Background image of page 1

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 2 Objectives Use the Boolean type and its basic operations Use the if statement to perform some statements while skipping others Use the for and while statements to perform (other) statements more than once Use Boolean variables and functions to control if and while statements Use the wait() message to temporarily suspend program execution
Background image of page 2
Alice in Action with Java 3 Flow Control Flow: sequence of steps for performing a user story Flow control statement: structure for managing flow Flow control statements used in previous chapters doInOrder : produces a sequential execution doTogether : produces a parallel execution Control statements introduced in the current chapter if : directs program flow along one of two paths for : directs flow into a fixed number of loops while : directs flow into an arbitrary number of loops
Background image of page 3

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 4 Flow Control (continued)
Background image of page 4
Alice in Action with Java 5 The Boolean Type A basic Alice type used to define Boolean variables A Boolean variable holds a value of true or false Other basic types: Number and Object Condition (Boolean expression) Produces a value of true or false Basis for decision-making in programs
Background image of page 5

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 6 Boolean Functions Return a value of true or false Can act as a condition in an if or while statement Many refer to an object’s bounding box Example: obj .isBehind( obj2 ) true , if obj ’s position is beyond obj2 ’s rear edge false , otherwise
Background image of page 6
Alice in Action with Java 7 Boolean Variables Used to store a value of true or false Can be used in condition for if or while statement How to create a Boolean variable Click create new variable (or parameter ) button Specify Boolean as variable (or parameter) type
Background image of page 7

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 8 Relational Operators Produce true or false values Six relational operators: == , != , < , <= , > , >= Located in functions pane of world ’s details area Most often used to compare Number values Example: hoursWorked > 40 hoursWorked is a Number variable true when more than 40 hours have been worked
Background image of page 8
Alice in Action with Java 9 Relational Operators (continued)
Background image of page 9

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 10 Boolean Operators Used to modify or combine relational operations Three Boolean operators: AND , OR , NOT Located in functions pane of world ’s details area Example: age is a Number variable Teen number compared to condition returns true
Background image of page 10
Alice in Action with Java 11 Boolean Operators (continued)
Background image of page 11

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

View Full DocumentRight Arrow Icon
Alice in Action with Java 12 Introducing Selective Flow Control Summary of a scene with a princess and a dragon Princess meets a mute dragon and asks questions Dragon shakes its head to respond yes or no Objective: write a shakeHead() method Requirements for shakeHead() Parameter: yesOrNo, a
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/27/2008 for the course INSY 3300 taught by Professor Wang during the Spring '08 term at UT Arlington.

Page1 / 58

ch04 - Alice in Action with Java Chapter 4 Flow Control...

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

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