Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-18-2012, 06:31 PM   PM User | #1
martynball
Regular Coder

 
Join Date: Nov 2007
Posts: 554
Thanks: 231
Thanked 0 Times in 0 Posts
martynball is an unknown quantity at this point
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;    
        }
    }

martynball is offline   Reply With Quote
Old 06-18-2012, 06:37 PM   PM User | #2
DaveyErwin
Regular Coder

 
Join Date: Aug 2010
Posts: 810
Thanks: 12
Thanked 168 Times in 166 Posts
DaveyErwin is on a distinguished road
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 .
DaveyErwin is offline   Reply With Quote
Users who have thanked DaveyErwin for this post:
martynball (06-18-2012)
Old 06-18-2012, 07:55 PM   PM User | #3
martynball
Regular Coder

 
Join Date: Nov 2007
Posts: 554
Thanks: 231
Thanked 0 Times in 0 Posts
martynball is an unknown quantity at this point
Thanks that was the problem
martynball is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:37 PM.


Advertisement
Log in to turn off these ads.