Ruby
This is a super efficient piece of code that simulates a dice.
def almost_dice
rand(7) # will output a number between 0 and 6.
end
#I want a dice that outputs a number between 1 and 6, so I have no other choice, right?
def proper_dice
d = almost_dice
while d = 0
d = almost_dice #Eventually, I'll get d != 0
end
return d
end
puts proper_dice
In ruby what could look like a test :
d = 0
is actually an assignment. Since the assignement always succeed, then the test always returns true, hence the infinite loop