<< Chapter < Page
  Teaching beginners to code     Page 4 / 9
Chapter >> Page >

Eventually all of the actions will be completed and the condition will be tested again.

Need to avoid infinite loops

Generally speaking, unless something is done in one of the actions to cause the test to eventually return false, control will never exit the loop.

In this case, the program will be caught in what is commonly referred to as an infinite loop.

Other possible structures

In some programming languages, there are structures other than sequence, selection, and loop that structured-programming experts are willing toaccept for convenience including:

  • The switch-case structure.
  • The do-until structure.
  • The for loop
  • The for-each loop

While sometimes more convenient than the three main structures, these structures are not required for the solution of programming logic problems.

Preview

In this module, I will present and explain the simplest example of a selection structure that I was able to write in Scratch without using variablesand without using relational or logical operators. (I will explain operators, including relational and logical operators in future modules.)

Screen output for the program named IfSimple01

The program places a basketball and two beach balls on the Stage as shown in Image 4 .

Image 4. user interface for the program named ifsimple01.

Missing image.
Image 4. User interface for the program named IfSimple01.

Click the green flag or the basketball

When the user clicks the green flag in the upper right corner, the three balls are placed in a horizontal line with the basketball in the center.

Scratch code, which can be paraphrased as shown in Image 5 , is executed each time the user clicks the basketball with the mouse.

Image 5. a paraphrased version of the scratch code.

when Basketball is clicked{ move basketball forward by 90 stepsif(Basketball is touching RightBeachball){ turn Basketball by 180 degrees}//end ifif(Basketball is touching LeftBeachball){ turn Basketball by 180 degrees}//end if }
Image 5. A paraphrased version of the Scratch code.

In other words, if you repetitively click the basketball with the mouse, it will move back and forth from left to right bouncing off of the two beach balls.The basketball will keep bouncing back and forth between the two beach balls for as long as you continue clicking on the basketball.

Discussion and sample code

Let's walk through the steps required to develop this program. I will deal first with the code that defines the behavior of the program when the userclicks the green flag in the upper right corner of Image 4 .

The Cartesian coordinate system The position of sprites on the Stage in the Scratch user interface is based on a two-dimensional Cartesian coordinate system with the origin at the center of the Stage.

Three sprites

Note in the lower right corner of Image 4 that this program contains two beach balls and one basketball in addition to the Stage.

You add sprites to your program by clicking on the button with the icon of the file folder in the grayarea immediately below the white Stage area in Image 4 .

When you click on one of the sprites that you have added to the program, that sprite appears at the top of the center pane. Having done that, you canthen drag programming blocks into the center pane that define the behavior of that sprite.

Questions & Answers

mcq creativity involves
Sanjika Reply
send me the answers
Sanjika
mCQ creativity involves
Sanjika
ology means a study of
SharaAmor Reply
is a greek word means soul
SharaAmor
science
Tina
a branch of knowledge
Kanchan
psych means soul and ology means to study.
Wajid
Can someone help me with tha latent functions of different social institutions
Usman
***interestinglydifferenttopics.blogspot.com/2020/10/reflexes-psychological-debate.html Do check this out and please correct me if I'm wrong anywhere in this
Interestingly Reply
Factors that affect learning?
Ofentse Reply
I am struggling with survivors guilt and complicated grief after traumatic death of spouse. how to cope.
Rowdy Reply
Try to talk with someone you trust and join people who makes you feel worthy. try to help someone. Helping someone makes you feel better
sherlock
I think you must seek professional help.
Swarada
I am extremely sorry for your loss...I know that the pain of your loss is overwhelming and that you are experiencing all kinds of difficult and unexpected emotions. please don't get me wrong but the best way to cope is to move on..i know its hard..but that's the only way..(continued.)
Princess
stop burdening yourself with thoughts that say you could have done something..you couldn't..your just a human being and you cant always be a superman who saves the day..please dont feel guilty when you have no reason to..(cont.)
Princess
learn to love yourself again..learn to live ..for yourself,for the people who love you and need you in their lives.live for people who you once loved...Think about how you can make your life meaningful once again.It might seem impossible but trust me its necessary ..
Princess
Let your feelings of pain out ..you dont have to suffer ..talk to people whom you trust and love. take care and have a beautiful life ahead.
Princess
First and foremost -- Wow Rowdy! You have been through a highly difficult situation in your life, hands down. As a wife, I simply cannot phathom nor imagine slightly the feelings and thoughts you bare and I'm sure as these words do not help and hit rewind; my heart and prayers are going out to you-
Stephanie
today. I will say as well, everything you are feeling and going through, please know that these feelings and thoughts are all allowed, it is okay for you to find yourself feeling or thinking things that you would never find yourself wanting especially given the situation. I'm sure you question --
Stephanie
yourself, which in turn could make you question who you are right now and what this means for you as a person now and in the future. This is all okay, but there will have to be an understanding as to how to grow from these feelings and thoughts in a more humane manner l as these feelings and ---
Stephanie
thoughts could take a turn for a much more negative outcome as you find yourself trapped in a darkness that, if strong enough, trials and tribulations take years of complex development and experience, less strong minded individuals sometimes either never find the light, or end up being stuck in ----
Stephanie
a subconscious netherworld as they are consumed given the manipulation that was not understood to overcome. It results in losing all sense of heart, faith, soul and intelligence so that you don't grow, which in your case, growth is crucial. This is what your spouse will do their best in trying -----
Stephanie
to guide you through; keep an your senses wide open so that you can learn when she is trying to communicate.
Stephanie
What is meant by politics of intelligence? Please guide about this article.
Ali Reply
***scholar.google.com/scholar?q=politics+of+intelligence&hl=en&as_sdt=0&as_vis=1&oi=scholart#d=gs_qabs&u=%23p%3D_ckggUkdkPUJ
Angela
Thanks angela
Ali
Can u please explain it to me in your words?
Ali
Information about child psychology
Mohammed Reply
what is this
Maryam
any theory recommendations about socialization?
Geo
help me please:<
Geo
actually I don't know
Maryam
I badly need some for my research :<
Geo
But I need that😥
Mohammed
***courses.lumenlearning.com /boundless-sociology/chapter/theories-of-socialization/
Jobin
branches of psychology
QSN Reply
neuropsychology
jeddy
behaviorism
Mira
Legal psychology
Miljana
Developmental psychology, Sports psychology , Clinical psychology , Marketing psychology , counseling psychology , Biological psychology, Educational psychology , Positive psychology etc.
Swarada
child.psychology
Nss
social, occupational psychology
jeddy
what does it mean when the temporal lobe is anterior to occipital lobe
John Reply
the cortex refers to what part of the brain
John
the cortex refers to what part of the brain
John
cerebral cortex
jeddy
behind?
jeddy
in what time of situation is training most useful?
marjelee Reply
during bad experience
Nyakuei
i think its not about suitation, its about the thing tatz need training.
gokul
training is possibly warranted for all situations.
rhoda
I would think that training should be an ungoing thing. That's before, during and after. just in case there's a reoccurrence
Angela
any time
Aaronz
what is Karma
ana Reply
I think the summation of good and bad deeds you do in your life. Accidentally or otherwise.
Swarada
Yes. I totally agree.
ana
And if it is bad then the root must have been too.
ana
Yes , In Hinduism we also believe that our parent's Karma also applies to us ! Don't know about that , but it kept people in check .
Swarada
Adding to Swarada point. karma can be good or bad. both will have consequences. karma is biasedness you have shown in your life. like a king could not have two rules for normal man and his son, that comes under karma.
Sujeet
Oh perfectly said!
Swarada
Ok. It is also said that when one does something... bad or good..it will come back to you 10 folds of the same.
ana
yea that too ! I remember my mother always said if u stole someone's 10 rupees ur 100 will be stolen ( excuse my English ! I'm a non - English speaking person)
Swarada
karma is nothing but what one usually mean when they say- what you sow, so shall you reap.
Alisha
certainly
Crazy
more important.. this concept was told by lord Krishna as part of spirituality, to focus on your good deed ,the purpose you are born for and your responsibilities. Not for hoping that bad will happen with people who made you feel bad. just giving example ;)
Sujeet
karma is the boomerang of your actions. what u put out in the universe u get back
David
Who is the founder of psychology
Daryl Reply
Wilhelm wundt
Amanda
Wilhelm Wundt
Sneha
William wundth
Ihrar
Wilhelm Wundt
Megha
and William James
Amanda
Wilhelm Wundt
adam
Wilhelm Wundt is the founder of structuralism
Angela
Yes and also the "Father of Psychology" I think the correct word is Father not Founder.
Swarada
oh ok. noted
Angela
i believe it goes beyond him I believe it is Ancient but un formalized
David
I like your answer Swarada
David
Oh thanks! But u summarised it well!
Swarada
what is up my fellow psych peeps!!
what are some academic research on developmental psychology
Chezy
Sawrada Founder of Psychology is W.Wundt but Father of Psychology is Sigmund Freud...
Wajid
what are some good schools to study psychology?
Enjoy Reply
George Mason, Penn State, UVA, university of Michigan
Jasmine
Hi I'm currently doing my experimental psychology research can you suggest a topic or research topic for my research thank you and please see 😊
Jerico Reply
Hello Jerico. I could help you out with some ideas if you're interested!
Yasmine
can u give me some ideas too?
Geo
For sure. It depends if you're trying to do an experiment (using statistics probably) or a case study what are you aiming for?
Yasmine
Hello Jerico. Try to opt for something simple and easy to do. I wouls say perhaps study the effects of color on concentration? You could get a group of people and have them take a memory test (you can find some online) in a white room for example. Then have them take another memory test
Yasmine
similar to the first one but in a different room and then you check the responses if the performance is better
Yasmine
but you have to know that a lot of factors will interfere in the performance such as mental state etc so make sure to choose a certain specific population. that's very important
Yasmine
you could be a bit more specific about it , to isolate the variables that can mess it up like age, sex, etc... you gotta take that into account
Yasmine
so that the results get somewhat accurate
Yasmine
that is very detailed information I really like it thank you very much 😊 your so very kind
Jerico
You're very welcome
Yasmine
what are your interests in general?
Yasmine
Althogh I'm persuing botany and engineering.... but I also want to study human behaviour and psychology.... I would like if anyone can share their knowledge with me !!!!
Crazy
I'm interested on effect of electroconvulsive therapy on people having a depression
Jerico
What is Electroconvulsive therapy?
Pixeled
Astral Projection
Mansi
Electroconvulsive therapy (ECT) is a medical treatment that is most commonly used in patients with severe major depression.
Jerico
What are the expected dutties functions and responsibilities of a head of an agency based on the principles, Practice of industrial psychology?
Paul Reply
what are the psychological characteristics expected from an employee wether regular or occupying a position?
Paul
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