java - How do you stop search in a loop once you meet the condition -
how stop each loop proceeding when condition false? because can let x = newx
when object in collection true condition. thank help. break won't help, tried.
for (char h : collection){ if ( condition == false ) { } else{ x = newx; } }
simplest way use break statement. want set new x value when elements of list passing condition.
boolean allmatch = true; (char h : collection) { if (!condition) { allmatch = false; break; } } if (allmatch) { x = newx; }
if want check if element sof loop matching condition can use java 8 feature:
boolean allmatch = list.stream().allmatch(element -> condition); if (allmatch) { x = newx; }
Comments
Post a Comment