add printf to while loop