<< Chapter < Page Chapter >> Page >

Viewing tip

I recommend that you open another copy of this module in a separate browser window and use the following links to easily find and view the imageswhile you are reading about them.

Images

  • Image A . Pseudocode for the program named ForeverLoop01.
  • Image B . Program code for the Scratch v1.4 version of the program named ForeverLoop01.
  • Image C . Program code for the Scratch v2.0 version of the program named ForeverLoop01.
  • Image D . Comparison between repeat and forever/if blocks.
  • Image E . Program code for the program named ForeverLoop02.
  • Image F . Pseudocode for the program named ForeverLoop02.
  • Image G . Pseudocode for the program named RepeatUntil01.
  • Image H . Program code for the program named RepeatUntil01.
  • Image I . Final screen output from the program named RepeatUntil01.
  • Image J . Blocks that can be used to create loop structures in v2.0.

General background information

In an earlier module, I told you that any programming logic problem could be solved using an appropriate combination of only three programming structures,none of which are complicated. The three structures are known generally as:

  • The sequence structure.
  • The selection or decision structure.
  • The loop, repetition, or iteration structure.

I have explained the sequence and selection structures and some of the loop structures in earlier modules. I will continue to concentrate on the loopstructure in this module.

Preview

In this module, I will present and explain the following three Scratch programs:

  • ForeverLoop01 - This program uses a forever block in conjunction with an if block to cause a sprite to move in a small circle while the space bar is pressed.
  • ForeverLoop02 - This program illustrates the creation of a counter loop using a forever block in conjunction with an if block.
  • RepeatUntil01 - This program uses a repeat until block to cause a sprite to run in a small circle until the user presses the spacebar.

In addition, I will provide the specifications for a student-programming project for you to demonstrate your understanding of what you learned from thethree programs listed above and from earlier modules.

Discussion and sample code

The program named ForeverLoop01

This program illustrates the use of a forever block in conjunction with an if block. When the user clicks the green flag, the program implements the pseudocode shown in Image A .

Image a. pseudocode for the program named foreverloop01.

Move the cat to the center of the stage. Turn the cat to face to the right.while(true){//infinite loop if(space bar is pressed){Change cat to next costume image Move cat forward 10 steps.Wait 0.1 seconds. Turn cat clockwise 15 degrees.}//end if statement }//end infinite while loop
Image A. Pseudocode for the program named ForeverLoop01.

If the space bar is pressed, the cat moves around the circumference of a small circle, appearing to walk due to the visual effect produced by switchingbetween two images (known in Scratch as costumes) . As explained in a previous module,the two costumes were designed to produce the illusion of walking.

Program code for the Scratch v1.4 version of the program named ForeverLoop01

The code for the older Scratch v1.4 version of this program is shown in Image B .

Image b. program code for the scratch v1.4 version of the program named foreverloop01.

Missing image.
Image B. Program code for the Scratch v1.4 version of the program named ForeverLoop01.

Questions & Answers

Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
SUYASH Reply
for screen printed electrodes ?
SUYASH
What is lattice structure?
s. Reply
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
Sanket Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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