For loop :- Genius student


  • The for loops used to check through a block of code a number of times.
  • Statement 1 is executed before the loop (the code block) starts.
  • Statement 2 defines the condition for running the loop (the code block).
  • Statement 3 is executed each time after the loop (the code block) has been executed.
Syntax
 for (statement 1; statement 2; statement 3) {
    //code block to be executed
}
Code:-


<!DOCTYPE html>
<html>

<head>
 <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

 <input type="button" onclick="fun_for()" value="Execute For loop">

 <script>
  function fun_for()
  {
   //step 1 => i=0 initizated
   //step 2 => check condition (0<3)
   //step 3 => If condition true execute the inside statements
   //step 4 => increment i++ (i=i+1) now i=1
   //step 5 => check condition (1<3)
   //step 6 => If condition true execute the inside statements
   //step 7 => Execute the function condinusly till condition is false (3<3)

   for (i = 0; i < 3; i++)
   {
    alert("i value is : " + i);
   }

  }
 </script>

</body>

</html>
For loop :- Genius student For loop :- Genius student Reviewed by Network security on October 14, 2019 Rating: 5

No comments:

Useful Information

Powered by Blogger.