for loop

Discussion in 'JavaScript' started by jennifer_48219, May 30, 2008.

  1. #1
    Hi everyone, I am using the for loop function. I feel that my code is correct but something is wrong. I check for brackets and semicolon and they are in the right places and the right amount.

    Can someone look at my code and let me know why it is not displaying/functioning. I am using the decrement operator with the for loop.
    This code should make my code look like
    0
    1
    2
    etc

     function ForTest()
    {
    	var OutPut="";	
    	FillArray()
    	for (var i=Numbers.length; i >= 0; i--)
    	{
    	OutPut = OutPut + Numbers[i] + "\r";
    	} 
    	document.frmMain.txtaOutput.value = OutPut;
    }
    Code (markup):
    and I also tried it this way
    function ForTest()
    {
    	var OutPut="";	
    	FillArray()
    	{
    	for (var i = Numbers.length - 1; i >= 0; i--);
    	{
    	OutPut = OutPut + Numbers[i] + "\r";
    	} 
    	document.frmMain.txtaOutput.value = OutPut;
    	}
    }
    Code (markup):
    neither way is making my document work.
     
    jennifer_48219, May 30, 2008 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    is Numbers defined?
     
    crath, May 30, 2008 IP
  3. swordbeta

    swordbeta Banned

    Messages:
    225
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Never seen such a like for loop before...do you know the basics?
    for(i = 0; i < 4; i++){
    document.write(i+"<br />");
    }
    Code (markup):
    Will print out:
    1
    2
    3
     
    swordbeta, May 31, 2008 IP
  4. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #4
    his for loop seems just fine
     
    crath, May 31, 2008 IP
  5. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You may need to use window.Numbers if this var is from the global scope. Give a bigger piece of code, cause that one is just fine, the problem is somewhere else in the code.
     
    xlcho, Jun 3, 2008 IP
  6. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    function ForTest(){
    	FillArray();
    	var OutPut = "", i = Numbers.length;	
    	for ( ; i >= 0; i--)
    		OutPut += Numbers[i] + "\n";
    	document.frmMain.txtaOutput.value = OutPut;
    }
    PHP:
    Post the FillArray() function.
     
    MMJ, Jun 3, 2008 IP
  7. sharry

    sharry Peon

    Messages:
    319
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #7
    yeah what is Numbers ???, let us know if its a global array ?
     
    sharry, Jun 7, 2008 IP
  8. soandky130

    soandky130 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Is Numbers a global array? If not, that may cause the failure.
     
    soandky130, Jun 11, 2008 IP