SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Please help me understand this loop syntax

  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
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,454
    Mentioned
    39 Post(s)
    Tagged
    1 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
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

  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
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,454
    Mentioned
    39 Post(s)
    Tagged
    1 Thread(s)
    You're welcome!
    It made me look twice, the first time I saw it
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

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
  •