When you type your post, there's a (?)
button at the top right corner of the edit box.
Press this button for detailed formatting help.
It will tell you that to format code nicely, you need to select it, then press the {}
button from above the edit box to format it. (You can press Ctrl+K, or Command+K on a Mac, to achieve the same.)
Alternatively you can manually indent each code line by four spaces to mark it as a code block.
There are formatting constructs for other things too, for example *word*
will be formatted in italics: *word*
. All the formatting constructs on StackExchange are designed to make the text of the post easily readable even when it wasn't processed by the formatting engine. For example, it's clear that *word*
is emphasized even if you look at it in plain text.