0
Integer evaluation with 'case'
Hello. I'm having a hard time trying to understand what is wrong with the code and why it's doesn't work as I expect : https://code.sololearn.com/cBB87KVpV26u/#rb The variation without user input. Same result. https://code.sololearn.com/ccy1E1wFc65a/#rb But it works like magic when I wrap this into the method and call it with a parameter: https://code.sololearn.com/cGkef6WmrM1G/#rb Any help would be appreciated :)
4 Réponses
+ 1
replace case n by n = case in the three examples and see what happens
+ 1
Thanks, Ivan. I read almost all of these articles before. In most examples "case n" form is fine. I'm still not sure what is going on here and it is actualy a surprise for me that it works even with simple "case" word, without "n = " or "n".
https://code.sololearn.com/cXJ5l2kkulDR/#rb
I rewrite the code a little. It looks better this way or not?
https://code.sololearn.com/cFizjf9s5831/#rb
0
Maybe this helps a little
http://stackoverflow.com/documentation/ruby/640/control-flow/3506/case-statement#t=201607220817347592243
http://stackoverflow.com/questions/948135/how-to-write-a-switch-statement-in-ruby
http://rubytutorial.wikidot.com/condiciones-loops
http://stackoverflow.com/questions/40899186/case-statement-and-comparison-with-integers
http://www.skorks.com/2009/08/how-a-ruby-case-statement-works-and-what-you-can-do-with-it/
0
Arkadly, good for you! titanic work!