Boolean in loop

Reading about Lookups I found new(for me) and awesome way to manage boolean value  used for controlling loops:



        boolean valid = false;
        while(!valid){
            id = this.getId();
            valid = true;
            for(IdValidator validator : rstl.allInstances()){
                valid = valid && validator.validate(id);
            }
        }
  
Using && really make me thinking why I didn't figure it out yet!

Comments

Popular posts from this blog

How to simulate slow connection (developer proxy in Node.js)

How to use NPM packages from private repositories on bitbucket