what's wrong with this script?

Discussion in 'ASP General' started by PeterB, Feb 4, 2005.

  1. PeterB

    PeterB Guest

    Hi!

    I have been looking at a script for downloading files from aspfaw.com:
    http://www.aspfaq.com/show.asp?id=2161

    It's the script for larger downloads (second larger code-block).

    Here's a snippet:

    Response.AddHeader "Content-Length", iSz

    For i = 1 To iSz \ chunk
    If Not Response.IsClientConnected Then Exit For
    Response.BinaryWrite adoStream.Read(chunk)
    Next


    What does "For" stand for that is after "Then Exit" (Then Exit For)? Isn't
    End If missing in that statement?

    thanks,

    Peter
     
    PeterB, Feb 4, 2005
    #1
    1. Advertising

  2. PeterB

    Phill. W Guest

    "PeterB" <> wrote in message
    news:%...
    > For i = 1 To iSz \ chunk
    > If Not Response.IsClientConnected Then Exit For
    > Response.BinaryWrite adoStream.Read(chunk)
    > Next
    >
    > What does "For" stand for that is after "Then Exit" (Then Exit For)?


    "For" stands for the [innermost] "For" Loop within which it appears.
    "Exit For" instructs VB to "drop out" of a loop, continuing with the
    next statement after the corresponding "Next".
    (It's a nice[r] way of doing a Goto out of a loop).

    > Isn't End If missing in that statement?


    No. This is the single-line form of If, which does not require a
    matching End If, and, as you've discovered, it's damnably confusing.
    I would /much/ prefer to see :

    For i = 1 To iSz \ chunk
    If Not Response.IsClientConnected Then
    Exit For
    End If

    Response.BinaryWrite adoStream.Read(chunk)
    Next

    I thought about this as well :

    For i = 1 To iSz \ chunk
    If Response.IsClientConnected Then
    Response.BinaryWrite adoStream.Read(chunk)
    End If
    Next

    which /looks/ cleaner still, but if the loop executes a *lot* of
    times and the client gets disconnected on one of the early iterations,
    you're wasting a whole load of processor time doing all the /other/
    iterations unnecessarily.

    HTH,
    Phill W.
     
    Phill. W, Feb 4, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miguel Dias Moura
    Replies:
    4
    Views:
    3,307
    Miguel Dias Moura
    Jun 23, 2004
  2. Matthew
    Replies:
    7
    Views:
    675
    Priscilla Walmsley
    Jan 7, 2005
  3. Rajat
    Replies:
    3
    Views:
    705
    Jorgen Grahn
    Jan 8, 2010
  4. VYAS ASHISH M-NTB837
    Replies:
    2
    Views:
    565
    Jan Kaliszewski
    Jan 7, 2010
  5. kath
    Replies:
    4
    Views:
    652
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page