<< Chapter < Page | Chapter >> Page > |
Eventually, either our stillHungry variable will be set to false, or the cookie box will become empty. At that point, the test will return false. Wewill terminate the loop and will stop eating cookies even though we might still be hungry for more cookies.
Most modern programming languages use the keywords while and for to implement loop structures such as this and you will see those keywords in useonce you get to Java, C++, C#, etc.
However, Scratch does not use those keywords to implement loops. Regardless, when I present pseudocode examples to explain Scratchprograms, I will continue to use while and for to get you accustomed to that terminology.
In this module, I will present and explain the following two Scratch programs:
In addition, I will provide the specifications for a student-programming project for you to demonstrate your understanding of what you learned from thetwo programs listed above. In addition, this programming project will require you to do some independent research into the manner in which Scratch sprites cancommunicate with one another.
This program illustrates the Scratch equivalent of a for loop (or something similar to a for loop) in other programming languages. In Scratch, it is called a repeat .
Why do I keep saying "something similar to a for loop?" The reason is that a for loop in other programming languages has many facets. Therepeat loop in Scratch is much more restricted than a for loop in those other languages.
This program places a cat sprite having two costumes on the stage. When the user clicks the green flag, code is executed that is equivalent to thepseudocode shown in Image C .
Most modern programming languages typically start counting with 0 instead of 1, but that is not necessarily the case with Scratch. You will learn more aboutthat when you get into Java, C++, C#, etc.
My purpose in providing the pseudocode is to help you better understand the Scratch code that follows. I am also preparing you for the use of otherprogramming languages later. I recommend that you compare the pseudocode with the Scratch code, and compareboth of them with what you see when you run the program.
This program contains several new code blocks that haven't been used in previous modules:
The only one of these blocks that I would put in the programming fundamentals category is the repeat block, and even the syntax of that block is quite a bit different from other modern programming languages.However, the other blocks are some of the things that cause Scratch programming to be fun, so I will use and explain such blocks as we go along.My only caution is that you should not expect to find those commands in other programming languages, at least not using the same syntax.
Notification Switch
Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?