What is a break statement:- genius student



  • The break statement can be used to come out of a loop and switch() statement.
  • We can able to terminate from the given label block.
  • A break statement must always be nested within any label it references.
Syntax
break [label];

Code:-

  • <!DOCTYPE html> 
    • <html> 
    •  
    • <head> 
    •  <meta name="viewport" content="width=device-width, initial-scale=1"> 
    • </head> 
    •  
    • <body> 
    •  
    •  <input type="button" onclick="fun_break()" value="break statement"> 
    •  <input type="button" onclick="fun_breaklabel()" value="break with label"> 
    •  
    •  <script> 
    •   function fun_break() 
    •   { 
    •  
    •    for (i = 0; i < 10; i++) 
    •    { 
    •     if (i == 3) 
    •     { 
    •      break; //Terminate the for loop 
    •     } 
    •     alert(i); 
    •    } 
    •  
    •   } 
    •  
    •   function fun_breaklabel() 
    •   { 
    •  
    •    block1: 
    •    { 
    •     block2: 
    •     { 
    •      alert(1); 
    •      break block1; // breaks out of both block2 and block1 
    •      alert(2); //Skip 
    •     } 
    •     alert(3); //Skip 
    •    } 
    •  
    •   } 
    •  </script> 
    •  
    • </body> 
    •  
    • </html>
    What is a break statement:- genius student What is a break statement:- genius student Reviewed by Network security on October 18, 2019 Rating: 5

    No comments:

    Useful Information

    Powered by Blogger.