Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

for Loop

for Loop
A repeat loop cycles though a group of statements until some condition is met. For instance, you can use a repeat loop to cycle though an array and print it to the screen. Or, you might want to cycle though the Array and look for some specific information using the if statement. The for loop is the most common used repeat loop. Here is the syntax for it.

Syntax:
 for ( [initial exp.]; [condition]; [update exp.] ){
    statement(s)

    }

The square bracket means that the parameter is optional. I always use all three parameters and think you will too.

The initial expression defines the starting point of the loop. It sets the value of a variable to some value. The condition tests the variable for a certain condition and when it is reached stops the loop and lets the code after for loop execute. The update expression determines how the variable is incremented.

Example:
Here is a simple example. We will use the "for loop" to print the numbers 1 through 5 to our screen.
var i
 for(i=1; i<=5; i++){
   document.write(i + "
")
   }

Results:
1
2
3
4
5
You can declare the variable as part of initial expression. In fact this is usually the way it is done. Here is our simple script with this change.

 for(var i=1; i<=5; i++){
   document.write(i + "
")
   }

 
     
   
JavaScript Tutorial
 
  Introduction
Introduction
  Object Oriented Programming
Object Oriented Programming
  How to
How to
  Where use JavaScript
Where use JavaScript
  Variables
Variables
  Operators
Operators
  if Statement
if Statement
  Switch Statement
Switch Statement
  Functions
Functions
  for Loop
for Loop
  while Loop
while Loop
  Popup Boxes
Popup Boxes
  break and continue Statements
break and continue Statements
  Events
Events
  Date and Time Object
Date and Time Object
  Special Characters
Special Characters
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Super Affiliate Strategies Ebook Super Affiliate Strategies
   
Download Secret Ultimate Supertip Ebook Secret Ultimate Supertip
   
Download Affiliate Marketing Mistakes & How To Make Sure You Avoid Them  Ebook Affiliate Marketing Mistakes & How To Make Sure You Avoid Them
   
Download Advanced Programming for the Java 2 Platform  Ebook Advanced Programming for the Java 2 Platform
   
Download Algorithmic Problem Solving  Ebook Algorithmic Problem Solving
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz