You can exit a code block by hitting Command Option Shift C. I found this out by hovering over the code block icon in the bar below the editor box.
The trick seems to be to add a blank final line, otherwise, it will not include the last line you typed in a code block.