+ 1

Problem with = and ==

I'm writing a program and I'm having problems with these: if c = 'binary' then while a >= 1 do b = b + String(a % 2) a = a / 2 end b.reverse puts b This outputs the correct answer, but displays this error: ..\Playground\:5: warning: found = in conditional, should be == When I fix this and replace = with == I get no error, but no output either.. What's the problem here? :/

16th Nov 2016, 7:52 PM
Stevan Marjanović
Stevan Marjanović - avatar
9 Answers
+ 5
Rewrite that if statement. if c == 'binary' And, considering this is Ruby, then your while loop shouldn't have a do at the end of it.
16th Nov 2016, 8:11 PM
Keto Z
Keto Z - avatar
+ 4
Not with Ruby, no. The then hasn't been in any languages (and as far as I know, QBASIC64 was the last major language to use it.)
16th Nov 2016, 8:16 PM
Keto Z
Keto Z - avatar
+ 3
You have one more problem. You have an end for your while loop, but not your if statement.
16th Nov 2016, 8:17 PM
Keto Z
Keto Z - avatar
+ 1
It has no then?
16th Nov 2016, 8:12 PM
Stevan Marjanović
Stevan Marjanović - avatar
+ 1
I did as you said, but I still get no output...
16th Nov 2016, 8:15 PM
Stevan Marjanović
Stevan Marjanović - avatar
+ 1
I'm learning in school to work with Delphi, and I'm pretty sure it does have then...
16th Nov 2016, 8:17 PM
Stevan Marjanović
Stevan Marjanović - avatar
+ 1
I have an end, but that's later in code
16th Nov 2016, 8:18 PM
Stevan Marjanović
Stevan Marjanović - avatar
+ 1
Heres the whole code x = gets a = gets.to_i b = '' if x == 'binary' while a >= 1 b = b + String(a % 2) a = a / 2 end b.reverse puts b elsif x == 'octal' while a >= 1 b = b + String(a % 8) a = a / 8 end b.reverse puts b end
16th Nov 2016, 8:20 PM
Stevan Marjanović
Stevan Marjanović - avatar
+ 1
oh, i found the problem. i need to use gets.chomp for x. and i was using only gets can you tell me difference between those. i dont understand the explanation on sololearn course... :/
16th Nov 2016, 8:24 PM
Stevan Marjanović
Stevan Marjanović - avatar