Ruby input in loops | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Ruby input in loops

hello, I am trying to write a stupid little game in ruby that picks two random numbers and the user must give the product of those two numbers. I want the playground to ask for three different products, so I am using a while loop. but the playground only asks for input once, and then for the second two loops it just puts the input at zero. anyone know how to fix this? I want the playground to ask for input for each iteration.

14th Oct 2017, 1:26 AM
Isaac Clemerson
Isaac Clemerson - avatar
4 Answers
+ 12
All input has to be fed to the compiler/interpreter prior to code compilation/interpretation. Loops and user input does not work well on Code Playground. You may have to alter the structure of your code to receive all input outside the loop. Split multiple input into different lines. E.g. 49 25 39
14th Oct 2017, 1:30 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
@Ace Yes, I believe it has always been this way.
14th Oct 2017, 4:41 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Ok that helps thanks!
14th Oct 2017, 1:54 AM
Isaac Clemerson
Isaac Clemerson - avatar
+ 2
sweet thanks!
14th Oct 2017, 2:28 AM
Isaac Clemerson
Isaac Clemerson - avatar