Rule1:Minimize the scope of local variables
keeping a variable out of block which is used only in block, exposes it to other code also . So as a thum rule use variable as and when required.
Make a method per activity to avoid mixing of variables of different activities.
As a point to note: for loops are better than while because all vaiables are declared and used in shortest possible scope,so less chances of error.