# Unspecified Syntax Error

**URL:** <https://www.ruby-forum.com/t/unspecified-syntax-error/49909>\
**Category:** Ruby\
**Created:** [December 9, 2005, 10:35pm UTC](https://www.ruby-forum.com/t/unspecified-syntax-error/49909 "2005-12-09T22:35:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![StarLion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@StarLion](https://www.ruby-forum.com/u/StarLion)\
**Post date:** [December 9, 2005, 10:35pm UTC](https://www.ruby-forum.com/t/unspecified-syntax-error/49909/1 "2005-12-09T22:35:26Z")

</div>

def MakeBoard  
rcount = 0  
puts “Push enter, then begin input. (For Input Format Compliance, extra  
enter key is necessary)”  
gets  
board = [0,0,0,0,0,0,0,0,0]  
9.times do  
instr = gets  
board[rcount] =  
[instr[0],instr[1],instr[2],instr[3],instr[4],instr[5],instr[6],instr[7],instr[8]]  
rcount += 1  
end  
return board  
end

def CheckBoard(board)  
complete = 1 #Is the puzzle complete?  
problems = 0 #Are there any problems?

#first, rows.  
h = 0  
9.times do  
g = 0  
group = [0,0,0,0,0,0,0,0,0]  
9.times do  
if board[h][g] == “.”  
group[g] = 0  
complete = 0  
else  
group[g] = board[h][g]  
end  
end  
problems = VerifyGroup(group)

#puts "Row " + h.to\_s + " Problems? " + problems.to\_s  
end  
#end Row Check

#next, columns.  
h = 0  
9.times do  
g = 0  
group = [0,0,0,0,0,0,0,0,0]  
9.times do  
if board[g][h] == “.”  
group[g] = 0  
complete = 0  
else  
group[g] = board[g][h]  
end  
end  
problems = VerifyGroup(group)  
#puts "Col " + h.to\_s + " Problems? " + problems.to\_s  
end  
##end Col Check

##Finally, the tricky one… the Boxes…  
startx = 0  
starty = 0  
curx = 0  
cury = 0  
count = 0  
group = [0,0,0,0,0,0,0,0,0]  
3.times do #Row Blocks  
3.times do #Cols Blocks  
3.times do #Rows of Block  
3.times do #Cols of Block  
if board[curx][cury] == “.”  
group[count] = 0  
else  
group[count] = board[curx][cury]  
end  
curx += 1  
end  
curx = startx  
cury += 1  
end #We now have a 3x3 block. Verify Data.  
problems = VerifyGroup(group)  
#puts "Box " + startx.to\_s + “,” + starty.to\_s + " Problems? " +  
problems.to\_s  
count = 0  
startx += 3  
cury = starty  
curx = startx  
end  
starty += 3  
startx = 0  
cury = starty  
curx = startx  
end

#Resolve the output.  
if problems == 0  
if complete == 1  
$output = $output + “You’ve done it!\n”  
else  
$output = $output + “Looking good so far…\n”  
end  
else  
$output = $output + “You’ve got a problem.\n”  
end  
end #FINALLY!

def VerifyGroup(group)  
#logic for Check  
flag = 0  
check = [0,0,0,0,0,0,0,0,0,0]  
group.each do |num|  
if check[num] == 0 && num != 0  
check[num] = 1  
else if num == 0  
check[0] = 0  
else  
flag = 1  
end  
num += 1  
end  
return flag  
end

$output = “”  
n = gets  
n.to\_i.times do  
board = MakeBoard()  
CheckBoard(board)  
puts $output  
end

Throws unspecified “Syntax Error” on 126 (last line of the code -  
‘end’)… no idea what’s going wrong?

---

<div class="post-metadata">

**Author:** ![StarLion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@StarLion](https://www.ruby-forum.com/u/StarLion)\
**Post date:** [December 9, 2005, 10:46pm UTC](https://www.ruby-forum.com/t/unspecified-syntax-error/49909/2 "2005-12-09T22:46:16Z")

</div>

this is what i see:

c:/r2.rb:11: syntax error  
[instr[0],instr[1],instr[2],instr[3],instr[4],instr[5],instr[6],instr[7],in¡str[8]]

^  
c:/r2.rb:11: Invalid char `\255’ in expression  
c:/r2.rb:11: syntax error  
[instr[0],instr[1],instr[2],instr[3],instr[4],instr[5],instr[6],instr[7],in¡str[8]]

^  
c:/r2.rb:136: syntax error

---

<div class="post-metadata">

**Author:** ![StarLion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@StarLion](https://www.ruby-forum.com/u/StarLion)\
**Post date:** [December 9, 2005, 10:50pm UTC](https://www.ruby-forum.com/t/unspecified-syntax-error/49909/3 "2005-12-09T22:50:19Z")

</div>

On Dec 9, 2005, at 3:35 PM, StarLion wrote:

> Throws unspecified “Syntax Error” on 126 (last line of the code -  
> ‘end’)… no idea what’s going wrong?

In my experience, this is almost always the sign of a missing “end”.  
If I add one to the bottom of your code, if does indeed go away. I  
can’t see where exactly it’s missing though. Try cleaning up your  
indentation, then it should be obvious.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![StarLion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@StarLion](https://www.ruby-forum.com/u/StarLion)\
**Post date:** [December 9, 2005, 10:49pm UTC](https://www.ruby-forum.com/t/unspecified-syntax-error/49909/4 "2005-12-09T22:49:16Z")

</div>

akonsu wrote:

> this is what i see:
> 
> c:/r2.rb:11: syntax error  
> [instr[0],instr[1],instr[2],instr[3],instr[4],instr[5],instr[6],instr[7],inï¿½str[8]]
> 
> ^  
> c:/r2.rb:11: Invalid char `\255’ in expression  
> c:/r2.rb:11: syntax error  
> [instr[0],instr[1],instr[2],instr[3],instr[4],instr[5],instr[6],instr[7],inï¿½str[8]]
> 
> ^  
> c:/r2.rb:136: syntax error

That doesnt appear when i try to execute… there is no \255 character  
where it says there is one. Maybe it’s because you’re copying off of the  
MB?

---

<div class="post-metadata">

**Author:** ![StarLion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@StarLion](https://www.ruby-forum.com/u/StarLion)\
**Post date:** [December 9, 2005, 10:58pm UTC](https://www.ruby-forum.com/t/unspecified-syntax-error/49909/5 "2005-12-09T22:58:31Z")

</div>

StarLion wrote:

> rcount += 1  
> 9.times do  
> problems = VerifyGroup(group)  
> 9.times do  
> ##end Col Check  
> 3.times do #Rows of Block  
> end #We now have a 3x3 block. Verify Data.  
> cury = starty  
> else  
> check[num] = 1
> 
> ‘end’)… no idea what’s going wrong?

Hi -

For starters, you’re gonna want to replace “else if” with “elsif”. The  
“else if” starts a second if, so using “else if” will leave you one  
“end” short. That’ll get you a syntax error for sure.

Regards,  
Matthew J Desmarais

---

<div class="post-metadata">

**Author:** ![StarLion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@StarLion](https://www.ruby-forum.com/u/StarLion)\
**Post date:** [December 9, 2005, 11:11pm UTC](https://www.ruby-forum.com/t/unspecified-syntax-error/49909/6 "2005-12-09T23:11:57Z")

</div>

> > 
> 
> Hi -
> 
> For starters, you’re gonna want to replace “else if” with “elsif”. The  
> “else if” starts a second if, so using “else if” will leave you one  
> “end” short. That’ll get you a syntax error for sure.
> 
> Regards,  
> Matthew J Desmarais

That… would do it, thanks. Now i just have to figure out my logic  
errors \>\_\<

---

<div class="post-metadata">

**Author:** ![StarLion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@StarLion](https://www.ruby-forum.com/u/StarLion)\
**Post date:** [December 9, 2005, 11:10pm UTC](https://www.ruby-forum.com/t/unspecified-syntax-error/49909/7 "2005-12-09T23:10:48Z")

</div>

StarLion wrote:

> else if num == 0

This should be:

elsif num == 0

I haven’t looked at the rest of the syntax, though, but I hope that  
helps.

Todd
