0

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 :)

4
  • You mean, you want to break the loop inside outputTable? Commented Dec 8, 2016 at 6:22
  • if is a conditional statement not a loop, there is a loop in the if condition some . Commented Dec 8, 2016 at 6:22
  • @SebastianKaczmarek Yes sir I want to stop outputTable when index > parseInt(searchLimit.val()) statement is true. Commented Dec 8, 2016 at 6:25
  • Then shouldn't the if statement be inside the outputTable loop? With the break line being just break;? Commented Dec 8, 2016 at 6:27

1 Answer 1

3

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++;
        }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Oh I did not realized that ! Thanks sir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.