<< Chapter < Page Chapter >> Page >

The program named ForLoop02

This program is an upgrade of the program named ForLoop01 . The behavior of this program is the same as the earlier program with the followingexceptions:

  • A slider variable named numberLoops is placed in the upper left corner of the Stage as shown in Image H .
  • When the user clicks the green flag, orthogonal axes are drawn through the origin of the Stage and the cat is placed at the origin.
  • When the user clicks the cat, the number of times the code in the repeat block is executed is determined by the current value of the slider variable.
  • As the code in the repeat block is repetitively executed, the path of the cat is traced out on the Stage as a series of short straightline segments, producing the circular path shown in Image I .

Image h. program forloop02 output after clicking the green flag.

Missing image.
Image H. Program ForLoop02 output after clicking the green flag.

Image i. program forloop02 output after clicking the cat.

Missing image.
Image I. Program ForLoop02 output after clicking the cat.

The program code

The code for this program is shown in Image J .

Image j. program code for the program named forloop02.

Missing image.
Image J. Program code for the program named ForLoop02.

Create a variable

The code in the left panel in Image J creates a variable with a slider named numberLoops and causes it to be displayed on the Stage as shown in Image I .

The initialization code

Although there is quite a lot of code that is executed when the green flag is clicked, there is nothing new there. All of that code has been explained in thisor earlier modules. For review, the green pen blocks and the blue go to blocks are used together to draw the Cartesian coordinates. Note that the pen is down when the initialization code finishes executing. As a result, a line willbe drawn whenever the cat sprite moves.

The repeat block

The only thing that is really new to this program is the use of the variable block named numberLoops to specify the number of times that the code in the repeat block will be executed each time the cat is clicked. Otherwise the code in the repeat block in Image J is the same as the code in the repeat block shown in Image F .

The operational difference

The operational difference is that each time the repeat block in Image F is executed, the code inside the repeat block will be executed 24 times. Each time the repeat block in Image J is executed, the number of times that the code inside the repeat block will be executed is specified by thecurrent position of the slider in Image I . This, in effect converts the static program named ForLoop01 into an interactive program in which the user has some control over the program behavior at runtime.

As mentioned earlier, because the pen is down, a line is drawn each time the cat sprite moves. That is what draws the circular path shown in Image I .

Online versions of these programs are available

Copies of these two programs have been posted online for your review (see Resources for the URL) . If you don't find the programs using that URL, search the Scratch site for the usernamed dbal.

Questions & Answers

who is called lender of the last resort
Divyanshu Reply
Hi
Linda
hlw
Karishma
Central bank
Majeed
hy
Karishma
Hello
Majeed
hy
Karishma
How are you
Majeed
Am gud
Linda
fine
Karishma
Am gud
Linda
hello
Chandra
Well! what's going on
Majeed
r u study in economics
Karishma
anybody there?
Chandra
r u study in economics
Karishma
the central bank
Sessay
Has completed already
Majeed
hey
neha
yes
Abigail
Yesss
Majeed
ok
Karishma
hey
Doctor
yh
Abigail
more questions
Sessay
how ar you
Doctor
split the price effect into income effect and substitution effect
Karishma
fine and u
Abigail
Hi
Godwin
hi
Hey, I am new here. Hope, discussion on Economics will clear our concepts more.
yasir
yes
Abigail
do u speak hindi or english
Karishma
how to consumer equlibrium through ic
Karishma
consumer equilibrium demand equals supply
Kenneth
the consumer is in equilibrium when the indifference curve is tangential to the budget line. or when the BL and IC intersect
Sessay
reasons indifference curve slopes downwards?
Kenneth
fine Abby any good,
Doctor
ur lost
Doctor
hey. im new year. economics teacher how we can discuss some thing interesting.
EDWINY
which one
Doctor
what do u understand the concept of poverty cycle.
EDWINY
hey
Ebong
I'm New here
Ebong
hi
ian
just new here guy's and also an Economics fresher of Kogi State University Anyigba
nelson
wxup
Ayegba
who can tell the laboratory of economic?
Amara
, Dennis Weissman Associates, LLC Laboratory Economics is the monthly business newsletter that gets behind the headlines and press releases.
Ayegba
sooo teah me what an LLC
Emmanuel
what's the topic
Adamsvictor Reply
economic systems
gracious
hello
Antonio
market
aba
hello where can I find the diagrams
Manu
Hello I am totally out ,I am not understanding why we are here. can someone help me out?
Amara
why Economic is not a pure science can someone help me out
Mohamed
because economics like science put forth a some hypotheses and then do experiments to prove them
Anwesh
but these experiments are not completely controlled
Anwesh
Hello
Comfort
hey
suraj
hi people can you help me out on "demand and supply"
Milton
Am not understanding can someone enlighten me pls
Bertilla
hi people can you help me out on "demand and supply"
Sessay
hello. if Mr.Patrick's income is #900.00 while that of Mr.Shodawe is #1300.00 if Mr.Patrick and Shodowe pay #90.00 and #130.00 as taxes,the tax system is?
Benjamin
I need the answer please
Benjamin
regressive tax system
shaikh
OK thanks
Benjamin
Isn't this called proportional tax rate because the rate stays the same - 10%? Tell me if I'm wrong
Ioan
Supply is perfectly elastic and demand increases.
kishore Reply
whose there
Waseem
show the demand curve
Hameed Reply
it slopes downward from left to right
Ama
how resources are allocated in a free economy
Charlotte Reply
explain how discriminating Monopoly increase profits
Charlotte
factors responsible for the emergence of monopoly situation
adelakun Reply
total output produced by a country over a given period of time .... can someone give me the term plz
TMM Reply
GDP
Anjorin
thaks man
TMM
Woman. 👍👍
Anjorin
gross domestic products
janet
GDP
Bertilla
GDP
Prof
GDP
Bertilla
gross domestic product
gross domestic product
GDp
Mohamed
gdp
agboola
what is recession pertaining to GDP
Prince
what is recession pertaining to GDP
Prince
what is recession
Prince
What is long run supply curve of a industry
Rashika Reply
enlightened
Ernest
all on board am here
Ernest Reply
am late I missed alot
Ernest
A mixed economy is the best type of an economy.Discuss
Tawanda Reply
Agreed Mixed economics is d combination of both capitalist and socialist economy, it give room for both individual and government to make decisions whereby giving room to a rapid development of d economy.
Anjorin
?
Andres
agreed
Ernest
Explain more about the Macroeconomics
Lizzy Reply
what is macroeconomic
Ekye
macro economics has to do with the of study economics at national level i.e the study of national economy as a whole. While micro is concerned with the study at individual, group or company level.
Andres
Andres explain
Ernest
ok
Ernest
scale and preference
Okodili Reply
please enlighten me
ANDREW
Please explain to me what ma economics
Lizzy
ok
Ernest
Views of classical economics with their modern economics
Mr Reply
sir bride me
Ernest
enlightenment
Ernest
what are the characteristic of economic laws
Eazy Reply
find out
Ernest
similarities of a command and a mixed economy
Talent Reply
seen
Ernest
Difference between extinct and extici spicies
Amanpreet Reply
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