# Each\_byte question

**URL:** <https://www.ruby-forum.com/t/each-byte-question/130066>\
**Category:** Ruby\
**Created:** [February 25, 2008, 4:32am UTC](https://www.ruby-forum.com/t/each-byte-question/130066 "2008-02-25T04:32:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmcdougal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bb73d2/32.png) [@lmcdougal](https://www.ruby-forum.com/u/lmcdougal)\
**Post date:** [February 25, 2008, 4:32am UTC](https://www.ruby-forum.com/t/each-byte-question/130066/1 "2008-02-25T04:32:50Z")

</div>

Hi,

I am new to Ruby(v 1.8.6),  
I will like to know if is possible to  
use multiple lines on a block for the each\_byte method on strings.

Something like:

coset=9  
i=0

message =  
“adsfasdfakjhkjhowerjkbvmzbcnvkfhoeiwrukfhzadsfhhfalkhweryiuwyoyqbvbv”

message.each\_byte do |letter|  
i=+1  
if i == coset  
puts  
else  
print letter  
end  
end  
this code will yield : syntax error, unexpected $end, expecting kEND  
Any explanation will be appreciated.  
Thanks  
-L

---

<div class="post-metadata">

**Author:** ![lmcdougal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bb73d2/32.png) [@lmcdougal](https://www.ruby-forum.com/u/lmcdougal)\
**Post date:** [February 25, 2008, 5:10am UTC](https://www.ruby-forum.com/t/each-byte-question/130066/2 "2008-02-25T05:10:57Z")

</div>

Hi Luis,

On Feb 25, 2:32 pm, Luis M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> message =  
> “adsfasdfakjhkjhowerjkbvmzbcnvkfhoeiwrukfhzadsfhhfalkhweryiuwyoyqbvbv”
> 
> message.each\_byte do |letter|  
> i=+1

i=0  
puts i # =\> 0  
i+=1  
puts i # =\> 1  
i+=1  
puts i # =\> 2  
i=+1  
puts i # =\> 1  
i=+5  
puts i # =\> 5

i will always be 1 (ie i = +1)  
you want i+=1

> –  
> Posted viahttp://www.ruby-forum.com/.

cheers,

---

<div class="post-metadata">

**Author:** ![lmcdougal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bb73d2/32.png) [@lmcdougal](https://www.ruby-forum.com/u/lmcdougal)\
**Post date:** [February 25, 2008, 7:34am UTC](https://www.ruby-forum.com/t/each-byte-question/130066/3 "2008-02-25T07:34:00Z")

</div>

Luis M. wrote:

> this code will yield : syntax error, unexpected $end, expecting kEND  
> Any explanation will be appreciated.

If I run your code here, it runs without error (well, i will always be  
1, so  
the if-part will never execute, but the program finishes successfully  
without  
error message).

---

<div class="post-metadata">

**Author:** ![lmcdougal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bb73d2/32.png) [@lmcdougal](https://www.ruby-forum.com/u/lmcdougal)\
**Post date:** [February 25, 2008, 4:49pm UTC](https://www.ruby-forum.com/t/each-byte-question/130066/4 "2008-02-25T16:49:26Z")

</div>

On Feb 25, 2008, at 9:12 AM, Luis M. wrote:

> > Luis M. wrote:
> > 
> > > this code will yield : syntax error, unexpected $end, expecting kEND  
> > > Any explanation will be appreciated.
> 
> hmm!!??  
> Thanks Sebastian  
> I will keep investigating then.
> 
> -L

$end means the end of file  
kEND means the ‘end’ keyword

So the error message is saying: “Hey, I ran out of code when I still  
expected to see an ‘end’ to close a block (‘do’), ‘if’, ‘for’,  
‘while’, etc.”

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![lmcdougal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bb73d2/32.png) [@lmcdougal](https://www.ruby-forum.com/u/lmcdougal)\
**Post date:** [February 25, 2008, 3:12pm UTC](https://www.ruby-forum.com/t/each-byte-question/130066/5 "2008-02-25T15:12:27Z")

</div>

Sebastian H. wrote:

> Luis M. wrote:
> 
> > this code will yield : syntax error, unexpected $end, expecting kEND  
> > Any explanation will be appreciated.
> 
> If I run your code here, it runs without error (well, i will always be  
> 1, so  
> the if-part will never execute, but the program finishes successfully  
> without  
> error message).

hmm!!??  
Thanks Sebastian  
I will keep investigating then.

-L
