the problem is - the most of your variables declared inside the loop should be initialized outside the loop - like len

so, obviosly, they should be declared outside the loop as well