SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    ohio
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    loop and variables

    Can one create a loop that defines say 6 variables:

    for example

    for (i=1;i<7;i+=1)

    {

    var+i = blah blah blah;

    }

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Why not use an array?

    Code:
    var myArray = new Array(6);
    
    for (i=0;i<6;i++)
    
    {
    
    myArray[i] = "Test Var" + i;
    
    }

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe he doesn't want an array ...
    Code:
    for (i = 1; i < 7; ++i)
    {
        window['var' + i] = 'variable#' + i; 
    }
    alert('var5 = ' + var5);
    http://jibbering.com/faq/faq_notes/s...ckets.html#aVa
    ::: certified wild guess :::

  4. #4
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Off Topic:

    Dude, your new avatar freaks me out man!

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hah ! Me too...I copped it off of google's image search (fabulous utility). Caught my eye, pronto. I think it's Andy Devine but who knows. Glad it's not me.
    ::: certified wild guess :::


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
  •