Loading ...
Sorry, an error occurred while loading the content.

Re: i need a detailed information on LOOP

Expand Messages
  • webdevtrb
    ... Loops let you repeat blocks of code. The loops supported by Javascript are: for, while, do...while, and for...in. The for loop described: It repeats a
    Message 1 of 5 , Mar 6, 2009
    • 0 Attachment
      --- In JavaScript_Official@yahoogroups.com, "nitesh_bangera007" <nitesh_bangera007@...> wrote:
      >
      > please provide me a detailed information on LOOP in javascript
      > And also give some example with cooding in loops
      >

      ---------------------------

      Loops let you repeat blocks of code. The loops supported by Javascript are: for, while, do...while, and for...in.
      The for loop described: It repeats a block of statements until a condition you specity is no longer met.

      The structure is as follows:
      for(start_condition; continue_condition; increment)
      {
      iterating statements
      }

      When the loop starts, the 'start_condition' intializes an incrementing variable with an assignment statement. After that, the incrementing variable is evaluated against the 'continue_condition' statemet to see if its value is true or false. If true, the iterating statements are executed, the variable incremented and evaluated again. Eventually, changes to the incrementing variable make the 'continue_condition' statement false, which causes the loop to stop.

      Here is a practical example:

      for(i = 0; i < 10 ; i++)
      {
      document.write("<BR>i = " + i);
      }

      So what this example is saying is:
      The variable i is set to 0 to start with and the associated block of code is run. Then, using the increment operator ( ++ ), the value 1 is added to i. The i < 10 condition is evaluated. If i is still less than 10, then the loop repeats. So what you will see with this code is that i, with a BR tag following will be written to the browser screen 10 times.

      hope this helps
    Your message has been successfully submitted and would be delivered to recipients shortly.