# Does a block always \*have\* to return something?

**URL:** <https://www.ruby-forum.com/t/does-a-block-always-have-to-return-something/242395>\
**Category:** GNU Radio\
**Created:** [June 22, 2015, 4:42am UTC](https://www.ruby-forum.com/t/does-a-block-always-have-to-return-something/242395 "2015-06-22T04:42:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [June 22, 2015, 4:42am UTC](https://www.ruby-forum.com/t/does-a-block-always-have-to-return-something/242395/1 "2015-06-22T04:42:23Z")

</div>

Hi

Will something like this in the work function be correct?

self.consume(0, len(input\_items[0])  
if (something):  
return  
else:  
out[:] = in0 \*\* 2 #example  
return len(output\_items[0])

When I say return nothing I mean, the block just flushes the data that  
it consumed and waits on the next samples.

Thanks  
Anil

---

<div class="post-metadata">

**Author:** ![anil\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anil\_y](https://www.ruby-forum.com/u/anil_y)\
**Post date:** [June 22, 2015, 9:02am UTC](https://www.ruby-forum.com/t/does-a-block-always-have-to-return-something/242395/2 "2015-06-22T09:02:20Z")

</div>

Hi Anil,

> Does a block always _have_ to return something?  
> What you mean is the work function. I know this is a bit nit-picky, but  
> there has always been a lot of confusion caused by exactly that: The  
> block is the whole instance of a class derived from gr.block, and the  
> work() (or general\_work()) is the method of that class which gets called  
> repeatedly at runtime. You can have state as properties of the instance.

I’m not quite sure what the effect of returning None (which is what  
happens when you don’t return something in python) is, because that  
NoneObject would then be handled through SWIF to C++, and I have no idea  
whether SWIG has a uniform way of converting NoneObjects to integers.

In essence: yes, general\_work() must always return a number, but in most  
cases it’s totally O.K. to return 0 if your block wasn’t able to produce  
output.

Best regards,  
Marcus
