0

I am new into ruby. I have the following code block:

a = 10

while a < 20 do
 puts "True"
a++

next unless a == 12
puts "This is not 12"
end


$end

However, I'm getting void value expression for a ==12.I have assigned 10 into it to begin with so I don't see why I'm getting void value.

2 Answers2

2

replace a++ by a += 1 should work.

Ruby has no ++ operator. No increment operator (++) in Ruby?

Community
  • 1
  • 1
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53
0

Suppose

a = 2

The following are all equivalent, returning 5.

a++ 3
a + +3
a + +
3
a++

3

Therefore,

a++

next unless a == 12

is the same as

a + +next unless a == 12

This generates a "void value expression" exception because next unless a == 12 does not return a value (to be sent to the method :+).

The fix, of course, is to replace a++ with

a = a + 1

or its abbreviated form

a += 1
Cary Swoveland
  • 106,649
  • 6
  • 63
  • 100