Control structures - the loop in Javascript
Topics

Control structures - the loop in Javascript

for loop

Javascript loop, Control structures, 
learn Javascript made easy, for
this is a symbol for the ease of understanding
Scroll right down and press the "sneak peak" button to see the code.

Click on the "Lorem" to see what a loop can do. The tag with the id "lorem" has got this event handler: onclick = "answer()"; This means that if you click on the tag (the text of the tag) the function answer() is executed. This is the loop: for(var i = 0; i < 10; i++). After the loop you can see the brackets in which you find the statement being looped (ten times). The statement is: hi = hi + "Hi! <br />"; What happens here? You have the variable called hi to which the text "Hi" and a break (<br />) is added. It continues adding content (not overwriting) and looping this ten times creates the output, that you see after clicking on the lorem text. Each time another "hi" and a break tag is added to the existing content of the variable, adding up to ten times "hi". Then the variable is sent to say_something where it is put into the tag with the id "lorem".

tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Scriptum javae idoneum est.




submit to reddit



Sneak peek of the server side code