Results 1 to 2 of 2

Thread: The variable seems right, but...

  1. #1
    Join Date
    Nov 2009
    Location
    Isfahan, Iran
    Posts
    229
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default The variable seems right, but...

    Hi,

    The following loop works:

    Code:
    <html>
    <body>
    <script type="text/javascript">
    var i=0;
    for (i=0;i<=5;i++)
    {
    document.write("The number is " + i);
    document.write("<br />");
    }
    </script>
    </body>
    </html>
    But the following doesn't:

    Code:
    <html>
    <body>
    <script type="text/javascript">
    var i=0;
    var x="i=0;i<=5;i++"
    for (x)
    {
    document.write("The number is " + i);
    document.write("<br />");
    }
    </script>
    </body>
    </html>
    I'd just like to create a simple variable.
    Please bear with me as I'm a newbie in JavaScript and let me know what I'm missing.

    Many thanks in advance!
    Rain Lover

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    x is a string variable which can not be used in the for next loop
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

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
  •