Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby while loop within if statement

Tags:

ruby

Using the following code in Ruby:

if (tickFormat.length > 12 && tickFormat.length < 24)
    i = 1
    while(i < tickFormat.length) do
        if (i%2 != 0)
          tickFormat.at(i)[1] = ''
        end
        i++
    end
end

I get an "unexpected keyword_end" for the 2nd "end" statement. If I remove the while loop the code runs without error. Any ideas?

like image 389
JohnGalt Avatar asked May 10 '26 21:05

JohnGalt


1 Answers

Try this:

if (tickFormat.length > 12 && tickFormat.length < 24)
  i = 1
  while(i < tickFormat.length) do
    if (i%2 != 0)
      tickFormat.at(i)[1] = ''
    end
    i += 1
  end
end

The i++ syntax doesn't work in Ruby

like image 193
MrYoshiji Avatar answered May 12 '26 15:05

MrYoshiji



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!