Refinansiering | Lainaa | Beste Rabatt Kredittkort | Strømpriser 2018 | Beste Boligalarm | Billigste Forsikring | Billigste Mobilabonnement | XLGodis Rabattkode
JavaScript programming

break statement javascript

Written by Tusher

For, while, do while loop, and looping statements to a switch statement in the case of special conditions are met and the break statement is used to come out of the loop.

Practice Project:

body{background: #FFC;

<script type = “text/javascript”>
var number=prompt(“You have to find out a secrect number. Please put a number 0-10 “, “”);
var i;
number = parseInt(number);
if(number == 5)
document.write(“<h2>Hurray!! You have wine.<br /> The secrect number is:”+number+”</h2>”)
var number=prompt(“Please,put a number again”);
document.write(“<h2>better luck for the next time.</h2>”)


Notepad: to open a file type from the menu at the top of layer code by clicking on the Save as File name: index.html, Save as type: All files, save and open the index.html file with the Mozilla Firefox project, similar to the Demo will be displayed.

The above example var number = prompt ( “You have to find out a secrect number. Please put a number 0-10”, “”); Through the browser, a prompt box (to receive input from a user’s guide) will be displayed. Users will ask you to input a number between 0 and 10. The number that the user must type the string value of the variable will be saved as a number.

var i; A variable must be declared in the for loop.

for (i = 0; i <10; i ++) for the loop has been set for the conditions. At the beginning of the variable i is 0; For each loop i ++ i will increase the value of one; i <10; 9. That will be the maximum value of i. That is a total of 10 times will lupat.

number = parse Int (number); Sting in the number of type integer variables have been changed.

if (number == 5) shows the value of a number between 5 stetaments will work if {} else {} If any value between Location stetaments go away.

  1. If the value of a number document.write ( “<h2> Hurray !! You have wine. <br /> The secrect number is:” + number + “</ h2>”) through the browser Hurray !! You have wine. The secrect number is: 5 will be displayed.

break; The statement stopped for lupat. i was in the general conditions for the loop will continue, but its value to 9 lupat break; As a statement of whether the value of i will be closed for lupat.

  1. If the number is not in the value of var number = prompt ( “Please, put a number again”); The number of new variables to receive the prompt box will appear.

if (i == 9) {document.write ( “<h2> better luck for the next time. </ h2>”)} have revealed that the value of i is 9 browser, better luck for the next time. The text will be displayed.


About the author