ruby - re-try logic in a simple loop -
i'm trying set bounds array later printed in console , summed. lower bound ($a) should less 50 , wrote code evaluate that, want re-prompt number if higher number typed. far, google , experimentation have failed me. def num_a print "pick number 1 50: " $a = integer(gets.chomp) until $a < 50 puts "um, try again please." # need here prompt response # until $a less 50 end end you restructure loop prompt , call gets both inside it: def num_a # start number doesn't meet condition = 50 # check if number meets condition yet until < 50 # ask user enter number print "pick number 1 50: " = integer(gets.chomp) # ask try again if number isn't under 50 puts "um, try again please." unless < 50 end # return entered value caller end also, i've shown in example, recommend avoiding use of global variables ( $a in case).