Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    i++ not working in loop :S

    For some reason the i variable is not increasing by 1 for each loop :S

    Here is the array:
    Code:
    r,w
    Array length is 2.

    Function:
    PHP Code:
    //Search arrays
    function array_search(array, src) {
        for ( var 
    0< array.lengthi++ ) {
            
    alert(i);
            if (array[
    i] == src) {
                return 
    true;
            } else {
                return 
    false;    
            }
        }


  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Quote Originally Posted by martynball View Post
    For some reason the i variable is not increasing by 1 for each loop :S

    Here is the array:
    Code:
    r,w
    Array length is 2.

    Function:
    PHP Code:
    //Search arrays
    function array_search(array, src) {
        for ( var 
    0< array.lengthi++ ) {
            
    alert(i);
            if (array[
    i] == src) {
                return 
    true;
            } else {
                return 
    false;    
            }
        }

    Because you return
    before the end of
    the first loop .

  • Users who have thanked DaveyErwin for this post:

    martynball (06-18-2012)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Thanks that was the problem


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •