var i = 0, n = 5, bquery = [], query, norez bquery[4] = 'query'; if ( !norez ) { do { query = bquery[i++]; } while(query == undefined && i<= n); } alert ( i );