Syntax error

ERROR

Test6.rb:4 syntax error, unexpected tSYMBEG, expecting kDO or '<' or '<'
e.times do+y:x|

test6.rb:5: syntax error, unexpected tSTRING_BEG, expecting kDO or '<'
or '<'
          puts "Looping #{y}"

test6.rb:7: syntax error, unexpected kEND, expecting $end]

ERROR

well here is the code

CODE

x = 1200
puts "Before the loop, x = #{x}"

3.times do|y:x|
  puts "Looping #{y}"
  x = y
end

puts "After the loop, x = #{x}"

CODE

···

--
Posted via http://www.ruby-forum.com/.

What are you expecting the "x:y" statement to do? I ask because I'm not
familiar with that syntax, and ":" doesn't appear alone on any list of
operators I've seen. Otherwise I only know it as the second operator of
the ternary operator ?:

In any case, what again are you trying to accomplish? There's probably
a better way that doesn't have a syntax error.

···

On Thu, 2010-09-30 at 20:50 -0500, Anthony Ob wrote:

ERROR

Test6.rb:4 syntax error, unexpected tSYMBEG, expecting kDO or '<' or '<'
e.times do+y:x|

test6.rb:5: syntax error, unexpected tSTRING_BEG, expecting kDO or '<'
or '<'
          puts "Looping #{y}"

test6.rb:7: syntax error, unexpected kEND, expecting $end]

ERROR

well here is the code

CODE

x = 1200
puts "Before the loop, x = #{x}"

3.times do|y:x|
  puts "Looping #{y}"
  x = y
end

puts "After the loop, x = #{x}"

CODE

Alex Stahl wrote:

What are you expecting the "x:y" statement to do? I ask because I'm not
familiar with that syntax, and ":" doesn't appear alone on any list of
operators I've seen. Otherwise I only know it as the second operator of
the ternary operator ?:

In any case, what again are you trying to accomplish? There's probably
a better way that doesn't have a syntax error.

Sorry I forgot to post this.

I was doing that above the summary in the code, above the output.

···

--
Posted via http://www.ruby-forum.com/\.

Sorry I forgot to post this.
http://rubylearning.com/satishtalim/ruby_blocks.html
I was doing that above the summary in the code, above the output.

If I read the example correctly, the colon (:slight_smile: should be a semi-colon
(;).

js

···

--
Posted via http://www.ruby-forum.com/\.

Got it - in your code, you typed ":", while the example uses ";".

And to expand a bit on what I typed below, the ":" is used to indicate
symbols, like ":x". So when you had the typo "|y:x|", ruby thinks
there's two items there - "y" and ":x".

···

On Thu, 2010-09-30 at 21:35 -0500, Anthony Ob wrote:

Alex Stahl wrote:
> What are you expecting the "x:y" statement to do? I ask because I'm not
> familiar with that syntax, and ":" doesn't appear alone on any list of
> operators I've seen. Otherwise I only know it as the second operator of
> the ternary operator ?:
>
> In any case, what again are you trying to accomplish? There's probably
> a better way that doesn't have a syntax error.

Sorry I forgot to post this.
http://rubylearning.com/satishtalim/ruby_blocks.html
I was doing that above the summary in the code, above the output.

John Sikora wrote:

Sorry I forgot to post this.
Learn How to Blog and Build Websites for Profit!
I was doing that above the summary in the code, above the output.

If I read the example correctly, the colon (:slight_smile: should be a semi-colon
(;).

js

I have done that and it says:
Test6.rb:4 syntax error, unexpected ';', tCOLON2 or '[' or '.'
3.times do |y;X|

test6.rb:5: syntax error, unexpected tSTRING_BEG, expecting kDO or '<'
or '<'
          puts "Looping #{y}"

test6.rb:7: syntax error, unexpected kEND, expecting $end]

···

--
Posted via http://www.ruby-forum.com/\.

Alex Stahl wrote:

Got it - in your code, you typed ":", while the example uses ";".

And to expand a bit on what I typed below, the ":" is used to indicate
symbols, like ":x". So when you had the typo "|y:x|", ruby thinks
there's two items there - "y" and ":x".

I realised that mistake of using : instead of ;
But I am still getting an error

Test6.rb:4 syntax error, unexpected ';', tCOLON2 or '[' or '.'
3.times do |y;X|

test6.rb:5: syntax error, unexpected tSTRING_BEG, expecting kDO or '<'
or '<'
          puts "Looping #{y}"

test6.rb:7: syntax error, unexpected kEND, expecting $end

···

--
Posted via http://www.ruby-forum.com/\.

Anthony Ob wrote:

John Sikora wrote:
  

Sorry I forgot to post this.
Learn How to Blog and Build Websites for Profit!
I was doing that above the summary in the code, above the output.
      

If I read the example correctly, the colon (:slight_smile: should be a semi-colon (;).

js
    
I have done that and it says:
Test6.rb:4 syntax error, unexpected ';', tCOLON2 or '[' or '.'
3.times do |y;X|

test6.rb:5: syntax error, unexpected tSTRING_BEG, expecting kDO or '<'
or '<'
          puts "Looping #{y}"

test6.rb:7: syntax error, unexpected kEND, expecting $end]

As the page notes, this was introduced in Ruby 1.9.1. I'm guessing you are using an older version.

-Justin

Test6.rb:4 syntax error, unexpected ';', tCOLON2 or '[' or '.'
3.times do |y;X|

test6.rb:5: syntax error, unexpected tSTRING_BEG, expecting kDO or '<'
or '<'
          puts "Looping #{y}"

test6.rb:7: syntax error, unexpected kEND, expecting $end

One other note: you have an uppercase X instead of a lower case x.

js

···

--
Posted via http://www.ruby-forum.com/\.

Justin Collins wrote:

Anthony Ob wrote:

    
As the page notes, this was introduced in Ruby 1.9.1. I'm guessing you
are using an older version.

-Justin

I was, then I downloaded and installed version 1.9.2

···

--
Posted via http://www.ruby-forum.com/\.

John Sikora wrote:

Test6.rb:4 syntax error, unexpected ';', tCOLON2 or '[' or '.'
3.times do |y;X|

test6.rb:5: syntax error, unexpected tSTRING_BEG, expecting kDO or '<'
or '<'
          puts "Looping #{y}"

test6.rb:7: syntax error, unexpected kEND, expecting $end

One other note: you have an uppercase X instead of a lower case x.

js

I looked at the code there was no uppercase x, I am baffled.

···

--
Posted via http://www.ruby-forum.com/\.

Anthony Ob wrote:

Justin Collins wrote:

Anthony Ob wrote:

    
As the page notes, this was introduced in Ruby 1.9.1. I'm guessing you
are using an older version.

-Justin

I was, then I downloaded and installed version 1.9.2

Yes, I saw the same error in 1.8.6 but not in 1.9.2.

js

···

--
Posted via http://www.ruby-forum.com/\.

I think that you are still using 1.8.6 when you get this. Look at the
value of RUBY_VERSION. I see the exact error message in 1.8.6.

js

···

--
Posted via http://www.ruby-forum.com/.

Works fine on 1.8.7.

···

On Thu, 2010-09-30 at 22:11 -0500, John Sikora wrote:

Anthony Ob wrote:
> Justin Collins wrote:
>> Anthony Ob wrote:
>>>>
>>>
>>>
>>
>> As the page notes, this was introduced in Ruby 1.9.1. I'm guessing you
>> are using an older version.
>>
>> -Justin
>
> I was, then I downloaded and installed version 1.9.2

Yes, I saw the same error in 1.8.6 but not in 1.9.2.

js

John Sikora wrote:

I think that you are still using 1.8.6 when you get this. Look at the
value of RUBY_VERSION. I see the exact error message in 1.8.6.

js

Sorry, my fault it was still, 1.8.6. My apologizes.

···

--
Posted via http://www.ruby-forum.com/\.

Alex Stahl wrote:

Works fine on 1.8.7.

I tried 1.8.6, and 1.9.2
and here is what I got:
http://img684.imageshack.us/img684/6434/errorwy.png

···

--
Posted via http://www.ruby-forum.com/\.

Anthony Ob wrote:

John Sikora wrote:

I think that you are still using 1.8.6 when you get this. Look at the
value of RUBY_VERSION. I see the exact error message in 1.8.6.

js

Sorry, my fault it was still, 1.8.6. My apologizes.

No problem. Have fun.

js

···

--
Posted via http://www.ruby-forum.com/\.