Simple Control Structures
Overview
In this lesson we will lean how control structures change the flow and execution of a program
Learner Outcomes
At the completion of this exercise:
- Understand the difference between do together and do in order
- You will be able to construct an if/Else statement as well as nested if/else statements
- You will be clear on what a boolean value is and how it works with conditional statements
- You will learn to use flow charts storyboards to design your programs
- You will understand how to use a loop effectively (both for loops and while loops)
Activities
- Answer the following questions
- List four different control structures used in creating a program in Alice.
- What type of function value is used to check a condition in an if/else statement?
- Describe what happens in an if/else statement when the instruction in the Else pare is Do Nothing?
- The following relational operation is avaliable in the World’s functions list a<=b
- Give an example of what “a” and “b” can represent.
- What type of value is obtained when this operation is evaluated?
- What is the purpose of a Loop statement?
- Alice does not have a built-in collision detection.
- What built-in function can be used to detect when one object is too close to another?
- Give an example of an instruction that uses the function to avoid collision.
- Do the following exercises:(remember to make storyboards)
- Blimp and DragonCreate a scene with a blimp(Vehicle) and a dragon(Medieval) in the air with the dragon facing the blimp. IN this fantasy scene, the dragon has found a blimp and is curious. The dragon flies around the blimp to check it out. Write a program to have the dragon move to the blimp and then fly around it (lengthwise) three times.
- Snowman to Stool This exercise uses a number function as the count for a loop. Create a world with a snowman and a stool (snowman behind and to the left of the stool) Use a loop to make the snowman(People) move to stool (Kitchen), one meter at a time. Use a distance to function to determine the number of times the loop repeats.(The distance to function might return a fractional distance such as 3.75 meters. The loop statement truncates the fractional number to the integer 3 and will repeat three times.) We recommend that you test your solution by moving the snowman and the stool to different locations on the screen and running the program with each change so you can know whether it worlds no matter where the snowman and the stool are located.
- Blimp and Dragon modified Modify the first program so the dragon spirals closer and closer to the blimp until it is almost on top of it then have the Dragon land on top of the blimp.
All done?
Save your program into your folder (be sure not to save it to the folder on the shared drive…do a save as. Then show your teacher your program.