Java: "for" change condition? -


while(result.length() != alltext){     b = (boolean)(i < variable);     for(i = firstr; b; i++){        //do }     b = (i < variable); } 

am can change condition boolean? in code b = condition converted true or false. want keep condition.

this:

b = (boolean)(i < variable); 

does not mean value of b "binds" condition i < variable. i.e. not mean when i changed value larger variable, b's value change. b assigned once.

you either put i < variable in loop condition, or can use lambda (predicate):

// assuming int intpredicate b = x -> x < variable;  // change loop for(i = firstr; b.test(i) ; i++){ 

if don't know lambdas are, represent anonymous classes. lambda expression in above code represents anonymous class:

new intpredicate() {     public boolean test(int x) {         return x < variable;     } } 

imo, should not use predicate. write condition should be. way easier understand loop in form:

for (i = x ; < y ; i++) 

than in form:

for (i = x ; b ; i++) 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -