<< Chapter < Page Chapter >> Page >
  • Changes to the next costume in the list. (In this program the list contains two costumes.)
  • Moves ten steps forward relative to its own orientation.
  • Pauses for 0.1 seconds.
  • Turns fifteen degrees counter-clockwise around its own center of rotation.

No screen shot of the output

Because this program is animated, a screen shot of the Stage wouldn't impart much information so I won't show you one. Basically, it would look very similarto Image I without the thought bubble. You can copy the code from Image C and insert it into your own program. Also, the program has been posted online so that youcan run it from there. (See the link to the online version in Resources .)

The program named ForeverLoop02

This program illustrates another usage of a forever block with an embedded if block. The behavior of this program is very similar to a program that I explained in anearlier module using the repeat block. However, there are major differences between the forever/if combination of blocks and the repeat block. Some of those differences are illustrated in Image D , which shows a repeat block at the top and a forever block with an embedded if block near the center.

Image d. comparison between repeat and forever/if blocks.

Missing image.
Image D. Comparison between repeat and forever/if blocks.

Comparison between repeat and forever/if blocks

One of the major differences is the shape of the blocks that can be dropped into the pockets on the repeat block and the if block.

The blocks with the rounded ends in the upper half of Image D , which generally produce numeric results, cannot be droppedinto the pocket with the pointed ends on the if block. The if block requires a boolean value of true or false.

However, the blocks with the rounded ends can be dropped into the pocket with rounded ends on the repeat block, which requires a numeric value.

The blocks with the pointed ends in the lower half of Image D can be dropped into the pocket on the if block. Generally speaking, those blocks produce a boolean result of true or false.

Curiously, the blocks with the pointed ends can also be dropped into the pocket with the rounded ends on the repeat block. That pocket needs a numeric value to specify how many times its embedded code will beexecuted. My unconfirmed guess is that when one of the boolean blocks with the pointed ends is dropped into a repeat block, a false value is treated as 0 and a true value is treated as 1.

No drop-in required for a repeat block

The repeat block doesn't require that any other block be dropped into the pocket to make it fully functional. All that is required isthat a literal value be entered into the pocket, or that the default literal value be accepted. Used in this way, the repeat block will cause the code inside the block to be executed a number of times matching the literal value.

A drop-in is required for the if block

On the other hand, the if block requires that another block, which evaluates to either true or false, bedropped into the pocket to make it functional.

The forever block is more versatile than the repeat block

In this program, I used a counter variable in conjunction with a less than block to produce a boolean result, thus causing the behavior of the forever/if block combination to be similar to the behavior of a repeat block. However, the forever block is much more versatile. The forever/if combination can be used to execute a seriesof code blocks on the basis of any block that you can construct that will evaluate to true or false.

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Teaching beginners to code. OpenStax CNX. May 27, 2013 Download for free at http://cnx.org/content/col11498/1.20
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?

Ask