SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Please help me understand this loop syntax

    Code JavaScript:
        for (var i = 0, f; f = files[i]; i++) {
        ParseFile(f);
        }

    I don't understand how you can have: var i = 0, f;

    I'm confused by the f. Am I just initializing f here and setting it to null? I can also read it as "var i = 0, then i = f".

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    Hi there,

    this:

    Code JavaScript:
    var i=0, f;

    is a shorthand version of:

    Code JavaScript:
    var i = 0;
    var f;

    So here, you are just initializing f

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for clearing that up for me, Pullo. Now it makes sense to me.

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    9 Thread(s)
    You're welcome!
    It made me look twice, the first time I saw it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •