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