Week 3

Interactive Programming, Conditional Logic, and While Loops

Author:Christopher Haynes
Email:chaynes@indiana.edu
Affiliation:Indiana University
Course:BL CSCI A201
Date:2008-01-22
Copyright © 2008, Christopher Haynes—all rights reserved.

Contents

Interactive Programming in Alice

Control of flow

Program input

Two kinds of input

Two kinds of animation

Alice events

Event handling methods

clicker Which of the following cannot cause an event in Alice?

  1. mouse click
  2. keyboard key press
  3. network activity
  4. mouse motion
  5. none (Alice can respond to any of the above)

Answer C

clicker Which of the following is not true of functions

  1. functions return values
  2. functions can take arguments
  3. functions can be used as instructions
  4. functions in Alice are associated with objects

Answer: C

clicker The most important consideration in program style is usually

  1. runtime efficiency
  2. clarity
  3. brevity
  4. originality

Answer: B

Demo: spotlight control

Demo interactive program specification

spotlightControl.a2w

Picture23.png

Basic event programming in Alice

Parameters and Event-Handler Methods in Alice

Demo scenario and program structure

Demo: spotlightControlPanel.a2w

Picture1.png


Demo concepts

Testing interactive programs

Functions in Alice

Demo: throwing a ball

Demo: throwBall.a2w

Picture3.png Picture4.png

New loop concept

How a function works

Picture2.png


Types of functions

How function are like methods

How functions differ from methods

clicker In Alice, method calls may have parameters

  1. in event handlers but not method bodies
  2. in event handlers and method bodies
  3. in only in method bodies
  4. nowhere

Answer: B

clicker In Alice return types are associated with

  1. functions
  2. methods
  3. functions and methods
  4. niether functions or methods, only variables

Answer: A

clicker In Alice

  1. functions and methods both may have return statements
  2. functions must have return statements but they are optional in methods
  3. functions always have return statements and methods never do
  4. functions and methods always have return statements

Answer: C

Bouncing ball demo main points

Demo: bounceBall.a2w

Picture5.png

bounceBall demo concepts

Fundamental programming concept: variable

Kinds of variables

Initialization of variables

Variables in Alice

Demo: looseBall.a2w

looseBall demo concepts

Demo: spotlightColorCycler.a2w

Picture7.png

Else-if control pattern

Else-if control picture

Picture8.png

Demo scenario

Demo: rabbitAct.a2w

Picture9.png
Picture10.png


Demo concept: Boolean operators

Boolean operators truth table

Inputs Output
A B A or B A and B not A
False False False False True
True False True False False
False True True False True
True True True True False

Demo concept: randomness

While: Indefinite Loops in Alice

Demo: looseBallandStop.a2w

Picture11.png


While statement flow of control

Picture12.png


Avoiding infinite loops

Loop how many times?

Demo scenario

Demo: flying.a2w

Picture13.png Picture14.png

Demo concept: nested loops

Two means of repetition

clicker In the Alice editor, where are boolean logic operators found?

  1. functions tab of any object's details
  2. methods tab of any object's details
  3. events editor frame
  4. functions tab of World's details

Answer: D

clicker Multiple logical conditions may be checked using:

  1. only nested if statements
  2. only boolean operators
  3. only multiple loops
  4. nested if statements or boolean operators

Answer: D

clicker Using Alice, my early experience with programming has been

  1. more enjoyable than expected
  2. less enjoyable than expected
  3. about as enjoyable as expected

clicker I would rather

  1. continue to program in Alice
  2. switch now to another language like Python that is more practical
  3. have skipped Alice and started with Python

Onward to Python!

Python vs. Alice: In general

Python vs. Alice: Syntax

Python vs. Alice: Types

Python vs. Alice: Bottom line

Python vs. other languages