It certainly looks weird. I would clarify that this is only an account that matters with a for loop:
for (int i = 0; i < inputSrcs.size(); i++) { System.out.println( "[ ]\t" ); }
I think this makes the intention clearer. Although, as noted in the comments, we really just replace one dummy variable with another in the above. I like that he explicitly calls size() , which, in my opinion, shows that size is important.
In a more expressive language, you can find something indicating "I just want to execute the body n times", which would be even more beautiful:
inputSrcs.size().times() { System.out.println( "[ ]\t" ); }
(This may or may not be valid Groovy :)
EDIT: I get another obvious answer that should have happened earlier:
printRepeatedly("[ ]\t", inputSrcs.size()); ... private static void printRepeatedly(String text, int count) { for (int i = 0; i < count; i++) { System.out.println(text); } }
Now in the calling method, the value is absolutely obvious ... and inside printRepeatedly we donโt even have a list context, so we could not try to use the data. For the time being, the dummy variable i is obviously a dummy variable, and the method name makes it obvious why we want this behavior.
source share