move check condition to outside in while block
Merge pull request #1758 from ksss/array-out-while

move check condition to outside in while block