asp function for each

Discussion in 'Programmer's Corner' started by chandrasekhar, Nov 20, 2010.

  1. chandrasekhar

    Thread Starter New Member

    Nov 5, 2010
    13
    0
    <%
    Response.Cookies("firstname")="Alex"
    Response.Cookies("user")("firstname")="John"
    Response.Cookies("user")("lastname")="Smith"
    Response.Cookies("user")("country")="Norway"
    Response.Cookies("user")("age")="25"
    %>


    <html>
    <body>

    <%
    dim x,y
    for each x in Request.Cookies
    response.write("<p>")
    if Request.Cookies(x).HasKeys then
    for each y in Request.Cookies(x)
    response.write(x & ":" & y & "=" & Request.Cookies(x)(y))
    response.write("<br />")
    next
    else
    Response.Write(x & "=" & Request.Cookies(x) & "<br />")
    end if
    response.write "</p>"
    next
    %>

    </body>
    </html>


    what is the use of "for each function in the above program.
    plz explain in detail:D
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,789
    It is a looping construct. Instead of using an index to select elements of an array the foreach construct assumes that the details of the structure and the number of elements are well known and so a loop index would be superfluous.
     
Loading...