In the last few days, I was looking for how to format a code block in my Google doc. After a few minutes I googled, I found a very useful Google Docs add-on Code Pretty. Just needs to select the code text you want to format and its “Format Selection” is pretty nice. The only con is that you cannot choose the programming language you want to format.
Another solution I found is an on-line syntax highlighter at http://markup.su/highlighter/
Just copy and paste into your document. Easy.