Syntax error

A

Anthony Ob

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
 
A

Alex Stahl

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.
 
A

Anthony Ob

Alex said:
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.
 
A

Anthony Ob

John said:
If I read the example correctly, the colon :)) 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]
 
J

Justin Collins

Anthony said:
John said:
If I read the example correctly, the colon :)) 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
 
A

Anthony Ob

Justin said:
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
 
A

Alex Stahl

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".
 
A

Anthony Ob

Alex said:
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
 
J

John Sikora

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
 
A

Anthony Ob

John said:
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.
 
J

John Sikora

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
 
A

Anthony Ob

John said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top