wrong condition for while

$count should be <=