Remember that band? I don't. I mean, what songs did they play? Oh yeah, you are right. Hot Blooded, Head Games, and who can forget Cold as Ice? I guess I can, actually. What did they have, a temperature fetish?
For...In is another way to loop. You use it when you want to loop though the values held in an array. I know we haven't covered arrays yet, but we will. For now just know that arrays are similar to boxes, like variables are. Except that where variables hold one value, arrays hold many values. Sort of like a box full of variables.
You can also use the For...In on variables and objects (we will discuss these later as well). For now though, let's loop through that array.
var mydogs = new Array()
mydogs = "Linus"
mydogs = "Charlie"
mydogs = "Violet"
mydogs = "Molly Volly"
mydogs = "Sally Anne"
mydogs = "Lucy (RIP)"
mydogs = "Schroeder (Enjoy the new home)"
for (dogs in mydogs)
document.write(mydogs[dogs] + "<br />")
You can tell several things from the above code: 1) I have too many dogs 2) I named them all after Peanuts characters (Molly Volly is Snoopy's tennis instructor) and 3) If I have any say in it (which I don't) my next dog will be named Pigpen.
Aside from that, here is how the program works. We create a variable named dogs, then an array named mydogs. We then assign the array 7 values (0 is the first value in the array). The values are my dogs' names. We then use the For...In statement to loop through the array and finally print out the values. Note that the For...In line is the one that says: for (dogs in mydogs)
Occurs when the loading of an image is interrupted
Occurs when an element loses focus
Occurs when the user changes a field
Occurs when a user's mouse clicks an object
Occurs when user double-clicks an object
Occurs when an error happens while loading a document or an image
Occurs when an element has focus
Occurs when a key on the keyboard is pressed
Occurs when a key on a keyboard is pressed or held down
Occurs when a keyboard key is released
Occurs when a page or an image finishes loading
Occurs when a mouse button is pressed
Occurs when a mouse is moved
Occurs when a mouse if moved off of an element
Occurs when a mouse is moved onto an element
Occurs when a mouse button is released
Occurs when the reset button is clicked
Occurs when a window or frame is resized
Occurs when text is Selected
Occurs when the submit button is clicked
Occurs when the user exits the page
Beautiful ain't it?
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.