Create min value, while and for loop