Home arrow JavaScript arrow Page 3 - Javascript: More Loops and Events
JAVASCRIPT

Javascript: More Loops and Events


In our last tutorial we covered functions and a portion of loops, leaving off at the While loop. In this tutorial we will continue with the Do While Loop and hopefully work our way through to a taste of JavaScript Events.

Author Info:
By: James Payne
Rating: 4 stars4 stars4 stars4 stars4 stars / 4
November 14, 2007
TABLE OF CONTENTS:
  1. · Javascript: More Loops and Events
  2. · Break Dancing
  3. · And So it Continues
  4. · Finishing Loops

print this article
SEARCH DEVARTICLES

Javascript: More Loops and Events - And So it Continues
(Page 3 of 4 )

The Continue statement is similar to the Break statement, only instead of breaking completely out of the loop, it simply breaks and continues to the next value.

  Behold!


<html>

<body>

<script type="text/javascript">

var i=0

for (i=0;i<=5;i++)

{

if (i==3){continue}

document.write("I drank this many beers: " + i)

document.write("<br />")

}

</script>

</body>

</html>

This will result in the print out:

  I drank this many beers: 0
  I drank this many beers: 1
  I drank this many beers: 2
  I drank this many beers: 4
  I drank this many beers: 5

As you can see, we skipped the number 3. Hey, you drink 5 beers and try counting! It is a very similar code to the Break, however we choose to not break completely out of the loop.

If you want to use this to make a funnier (or sadder if you really count like this) program you could do this:


<html>

<body>

<script type="text/javascript">

var i=0

for (i=0;i<=4;i++)

{

if (i==3){continue}

document.write("Look at me I can count!... " + i)

document.write("<br />")

}

var i=0

for (i=6;i<=7;i++)

{

if (i==7){continue}

document.write("Look at me I can count!... " + i)

document.write("<br />")

}

var i=0

for (i=8;i<=10;i++)

{

if (i==9){continue}

document.write("Look at me I can count!... " + i)

document.write("<br />")

}

</script>

<p><b>I R SMARTED!</b></p>

</body>

</html>

Here I have used several Loops and Continues to achieve this effect:

  Look at me I can count!... 0
  Look at me I can count!... 1
  Look at me I can count!... 2
  Look at me I can count!... 4
  Look at me I can count!... 6
  Look at me I can count!... 8
  Look at me I can count!... 10


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials