|
| |||||||||
| Tags: break, c program, continue, javascripts, loop, statements, switch |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| 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...| |===================| |
|
#2
| ||||
| ||||
| 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 ramATI 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 |
|
#3
| ||||
| ||||
| 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. |
|
#4
| ||||
| ||||
| 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” Code: var iNum = 0;
for (var i=1; i < 10; i++) {
if (i % 5 == 0) {
continue;
}
iNum++;
}
alert(iNum); //outputs “8”
__________________ Signatures reduce available bandwidth |
|
#5
| |||
| |||
| 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> |
|
#6
| ||||
| ||||
| 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 :
|
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |