if you define equals variable inside first for loop you can remove the reseting equals=false from line 31