Reputation: 513
I want to make some part of my code stop looping, but keep looping for another variable. How can I possibly do that ? I tried this code but it's not working
// Looping based on number of data
for ( var i = 0; i < data.length; i++ ) {
// Looping HTML table data output
if ( !search || data[i].some(someSearch) ) {
// Output table HTML + indexing number
outputTable: {
output += '<tr>';
output += '<td>' + index + '</td>';
for ( var j = 0; j < data[i].length; j++ ) {
output += '<td>' + data[i][j] + '</td>';
}
output += '</tr>';
index++;
}
// Data display limitation
// based on combobox value
if ( index > parseInt(searchLimit.val()) ) {
break outputTable;
}
}
// Count filtered data
searchFiltered++;
}
From that code, I want to break the part of code inside outputTable
label, but keep searchFiltered
looping. Can someone help me? Thanks :)
Upvotes: 0
Views: 135
Reputation: 15393
No need to use break
statement here. Put if condition like this. Every time the index
value check it is lesser than parseInt(searchLimit.val())
. if it is not it exit the if statement.
if ( index < parseInt(searchLimit.val()) ) {
outputTable: {
output += '<tr>';
output += '<td>' + index + '</td>';
for ( var j = 0; j < data[i].length; j++ ) {
output += '<td>' + data[i][j] + '</td>';
}
output += '</tr>';
index++;
}
}
Upvotes: 3