Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , ,

Sponsored Links



How to use Break and Continue Statements in JavaScripts?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-01-2010
warehouse peon's Avatar
Member
 
Join Date: Aug 2006
Posts: 111
How to use Break and Continue Statements in JavaScripts?

I have done the C and C++ programming languages. Now I have turned to the scripting languages few months before. I have started with the JavaScript. In that I am unable to use the break and continue statements.!! Can anybody explain me, how to use Break and Continue Statements in JavaScripts.?? Also Please provide me some sample of coding so that I can understand the concept more clearly.
Thanks in Advance..!!
__________________
|===================|
|YAY if that made sense...|
|===================|
Reply With Quote
  #2  
Old 30-01-2010
MELTRONICS's Avatar
Member
 
Join Date: Aug 2006
Posts: 226
Re: How to use Break and Continue Statements in JavaScripts?

If you want the control over the code of the loop, you can use the break and continue statements. Because the break and continue statements provide stricter control over the execution of code in a loop. As the words suggests, the break statement will break the loop and continue executing the code that follows after the loop. The break statement exits the loop immediately and doing this prevents the further repetition of the code. On the other hand, continue statement exits the current repetition.
__________________
3.2 (northwood)
2gig ram
ATI AIW X800xt 256mb
Gigabyte GA-8knxp 875p Chipset
Optiwrite 8X DVD Burner
Win XP PRO Sp2 (Works Perfectly)
2 SATA Raptor 74gig Raid 0
2 7200 IDE 320gig HD
Reply With Quote
  #3  
Old 30-01-2010
Solitario's Avatar
Member
 
Join Date: Aug 2006
Posts: 220
Re: How to use Break and Continue Statements in JavaScripts?

The following code demonstrates more about the break statements. I think that it will help you to understand. Here is an example for the break statement :
HTML Code:
<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=15;i++)
  {
  if (i==5)
    {
    break;
    }
  document.write("The number is " + i);
  document.write("<br />");
  }
</script>
</body>
</html>
__________________
I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.
Reply With Quote
  #4  
Old 30-01-2010
Viensterrr's Avatar
Member
 
Join Date: Jul 2006
Posts: 232
Re: How to use Break and Continue Statements in JavaScripts?

The following examples will let you know about the difference between the Break and the Continue Statements. First have look at the Break Statement :
Code:
 var iNum = 0;
for (var i=1; i < 10; i++) {
   if (i % 5 == 0) {
      break;
   }
   iNum++;
}
alert(iNum); //outputs “4”
Now check the Continue Statement :
Code:
var iNum = 0;
for (var i=1; i < 10; i++) {
   if (i % 5 == 0) {
      continue;
   }
   iNum++;
}
alert(iNum); //outputs “8”
In Continue Statement, the alert displays “8” , the number of times the loop has been executed. when i reaches a value of 5, it returns to the top and the continue statement is executed, causing the loop to skip the expression iNum++.
__________________
Signatures reduce available bandwidth
Reply With Quote
  #5  
Old 30-01-2010
Member
 
Join Date: Nov 2008
Posts: 1,193
Re: How to use Break and Continue Statements in JavaScripts?

Before looking at the combination of both the statements, I would like to recommend you to just have a look on single statements. Since, you have got the coding of the Break statement already, I am providing you with the Continue statement. The continue statement will break the current loop and continue with the next value. Here is the coding for that :
HTML Code:
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=15;i++)
  {
  if (i==5)
    {
    continue;
    }
  document.write("The number is " + i);
  document.write("<br />");
  }
</script>
</body>
</html>
Reply With Quote
  #6  
Old 30-01-2010
Warner's Avatar
Member
 
Join Date: Mar 2008
Posts: 349
Re: How to use Break and Continue Statements in JavaScripts?

In simple language, you can say that we use the break statement to terminate a loop, switch, or label statement. The syntax of the break statement is given below, it can either first or second :
  • break;
  • break label;
If you use the first option, which is break without a label, it terminates the innermost enclosing while, do-while, for, or switch immediately and transfers control to the following statement. And if you use the second option, break with a label, it terminate the specified labeled statement.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use Break and Continue Statements in JavaScripts?"
Thread Thread Starter Forum Replies Last Post
Difference between Titan Break 1 and Titan Break 2 in Infinity Blade 2 TeesMaar Video Games 5 14-12-2011 06:09 PM
How to use Break and Continue in PHP? NIcaBoy Software Development 5 06-03-2010 04:41 AM
Difference between DML statements and DDL statements Prashobh Mallu Software Development 5 11-01-2010 01:07 PM
SQL statements with JSP blindsleeper Software Development 2 16-05-2009 10:54 PM
RSS Implementaion in JavaScripts Jagdish Gada Software Development 4 16-03-2009 03:12 PM


All times are GMT +5.5. The time now is 05:23 AM.