H I O X INDIA
Javascript Tutorial
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
Español  Français  中文  Deutsch 
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Java-Script Tutorial
Introduction
Variables
Operators
Statements
Loops
Functions
Objects
Arrays
Browser Objects
Form DOM
Ask Your Doubts
More about Javascript
Feedback


Continue Statement


Topic

How to terminate or stop from a loop for only one iteration in javascript?



Explanation

continue statement:
        Continue statement is used to stop or terminate one iteration of the loop in execution. It is used in "for, while, do-while" looping statements. Continue statement unlike break statement does not completely terminate the loop. It stops processing for only one iteration and brings the control back to the beginning of the loop.

For an example, we will try to stop processing inside a for loop when i is 2.
Example Code:
<script language="javascript">
for(var i=0; i<5; i++)
{
       if(i == 2)
          continue;
        document.write("i is - "+i);
}
</script>


Result:

The example worked as follows,
a) This for loop has five iterations from i=0 to i=4.
b) It executes document.write at every iteration.
c) when i is 2 the condition above document.write becomes true and so continue statement is called.
d) continue statement terminates the looping sequence and brings the control to the beginning of loop, starting the next iteration.
e) Thus the print was not done for i as 2.




        Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

privacy policy     license     sitemap
© 2004-2005 HIOX INDIA - hioxindia.com

Other Links