did you use do {} while()   construction instead of  while() {}  for a specific reason ?  unless you want the statements in 'd' block to be executed at least once before checking the condition in while lopp, while() {} construction is the preffered