Back
Basically, if you want to stop a for loop, you can use the break statement:
var remSize = [], szString, remData, remIndex, i;/* ...I assume there's code here putting entries in `remSize` and assigning something to `remData`... */remIndex = -1; // Set a default if we don't find itfor (i = 0; i < remSize.length; i++) { // I'm looking for the index i, when the condition is true if (remSize[i].size === remData.size) { remIndex = i; break; // <=== breaks out of the loop early }}
var remSize = [],
szString,
remData,
remIndex,
i;
/* ...I assume there's code here putting entries in `remSize` and assigning something to `remData`... */
remIndex = -1; // Set a default if we don't find it
for (i = 0; i < remSize.length; i++) {
// I'm looking for the index i, when the condition is true
if (remSize[i].size === remData.size) {
remIndex = i;
break; // <=== breaks out of the loop early
}
I hope this will help.
Want to become a Java Expert? Join Java Course now!!
Want to know more about Java? Watch this video on Java Course | Java Tutorial for Beginners:
31k questions
32.8k answers
501 comments
693 users