Welcome Guest! (App Version 3.1)

websitnero logo name

Loops

Loops are used to iterate over a certain set of values for a number of times, to carry out some calculation or operation.

Following are the 3 kinds of loops:

  • For Loop
  • While Loop
  • Do While Loop

For Loop

This loop is the simplest one and used mostly for making all iterations.

Example

<button onclick="alpha()"> Click </button>

<script>
function alpha(){
  for(i=0;i<5;i++){
    alert(i);
  }
}
</script> 

While Loop

This loop is same as for loop, just the syntax and way of implementation is different.

Example

<button onclick="alpha()"> Click </button>

<script>
var i = 0;
function alpha(){
  while(i<5){
    alert(i);
    i++;
  }
}
</script> 

Do-While Loop

This loop is just the same as while loop; The only difference is that this loop will run at least once. This is very rarely or nearly never used in practical applications.

Example

<button onclick="alpha()"> Click </button>

<script>
var i = 0;
  function alpha(){
  do{
    alert(i);
    i++;
  }while(i<5);
}
</script> 
WebsiteNero is highly optimized for learning various website developing technlogies. We try our best to add maximum modules and examples to help learn the concepts clearly and vividly. We try to present all content and examples as simple as we can removing any complexity to hurdle easy understanding. We try best provide you with worthful content, but we cannot guarantee full correctness of all the content on this site. While using this website, you agree to have read and accepted all our terms of use and conditions, cookie, and privacy policy. Copyright, 2013-2018 by websitenero.com. All Rights Reserved.