Branching and Looping Examples, cont - PowerPoint PPT Presentation

About This Presentation
Title:

Branching and Looping Examples, cont

Description:

genericTripleJumpWhile.a2w genericTripleJumpLoop.a2w A Sentinel Sailing Loop Sailboat will turn to face the object Will sail one meter forward This process ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 70
Provided by: usersDrew2
Learn more at: https://users.drew.edu
Category:

less

Transcript and Presenter's Notes

Title: Branching and Looping Examples, cont


1
Branching and Looping Examples, contd
2
Remember the generic triple jump world
3
(No Transcript)
4
Lets change this to be interactive.
5
(No Transcript)
6
User input functions in Alice
  • ask user for a number
  • ask user for yes or no
  • ask user for a string

7
(No Transcript)
8
  • Start Alice and open genericTripleJump
  • Look at world. my first method
  • Note that the statements there form a linear
    sequence.
  • We want to modify this algorithm.

9
(No Transcript)
10
  • The first step is to add an If/Else instruction
    to the method.
  • Drag a copy of the If/Else tile from the bottom
    of the editor area.
  • Drop it into the method just below the three jump
    instructions.

11
Adding If/Else instructions
  • When adding an If/Else, you will be prompted to
    choose between true and false as an initial
    value for the condition.
  • This value is merely a placeholder.
  • We will always replace this value with a Boolean
    expression of a condition we want to test.

12
  • Replace the placeholder condition in the If/Else
    instruction with a function.
  • We need the function that will allow us to ask
    the user a yes/no question.

13
(No Transcript)
14
(No Transcript)
15
(No Transcript)
16
(No Transcript)
17
(No Transcript)
18
  • We want Alice to jump only if the user answers
    yes to our query.
  • Need to move the instruction that causes Alice to
    jump to the If clause of our If/Else instruction.

19
(No Transcript)
20
(No Transcript)
21
(No Transcript)
22
(No Transcript)
23
(No Transcript)
24
(No Transcript)
25
(No Transcript)
26
(No Transcript)
27
(No Transcript)
28
(No Transcript)
29
(No Transcript)
30
(No Transcript)
31
(No Transcript)
32
(No Transcript)
33
  • genericTripleJumpWhile.a2w
  • genericTripleJumpLoop.a2w

34
A Sentinel Sailing Loop
  • Sailboat will turn to face the object
  • Will sail one meter forward
  • This process continues until the sailboat is
    within 5 meters of the object
  • While (NOT (the sailboat is within 5
    meters of the object))
  • turn to face object
  • move forward 1 meter

35
A Sentinel Sailing Loop
  • Lets create a sail to method that will work with
    any object.
  • It should accept the target object as an input
    parameter.
  • This will be similar to the way the primitive
    move method accepts direction and amount

36
(No Transcript)
37
(No Transcript)
38
(No Transcript)
39
(No Transcript)
40
(No Transcript)
41
(No Transcript)
42
(No Transcript)
43
A Sentinel Sailing Loop
  • Sailboat will turn to face the object
  • Will sail one meter forward
  • This process continues until the sailboat is
    within 5 meters of the object
  • While (NOT (the sailboat is within 5
    meters of the object))
  • turn to face object
  • move forward 1 meter

44
(No Transcript)
45
(No Transcript)
46
(No Transcript)
47
(No Transcript)
48
(No Transcript)
49
(No Transcript)
50
A Sentinel Sailing Loop
  • Sailboat will turn to face the object
  • Will sail one meter forward
  • This process continues until the sailboat is
    within 5 meters of the object
  • While (NOT (the sailboat is within 5
    meters of the object))
  • turn to face object
  • move forward 1 meter

51
(No Transcript)
52
(No Transcript)
53
A Sentinel Sailing Loop
  • Sailboat will turn to face the object
  • Will sail one meter forward
  • This process continues until the sailboat is
    within 5 meters of the object
  • While (NOT (the sailboat is within 5
    meters of the object))
  • turn to face object
  • move forward 1 meter

54
(No Transcript)
55
(No Transcript)
56
(No Transcript)
57
Lets generalize sailTo so that we can sail to
any object.
58
(No Transcript)
59
(No Transcript)
60
(No Transcript)
61
(No Transcript)
62
(No Transcript)
63
(No Transcript)
64
(No Transcript)
65
(No Transcript)
66
(No Transcript)
67
(No Transcript)
68
(No Transcript)
69
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com