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).


Comments

  1. Arguably the most exciting technology currently on the .NET Framework, .NET Core is an open-source general-purpose development platform that Microsoft and the wider .NET community maintain. If you are a freelance net full stack developer, you can get more relevant projects on Eiliana.com, where top clients regularly post IT development projects.

    ReplyDelete

Post a Comment

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -