You can definitely copyright code. I think the English term "copyright" is a bit misleading. In German it is "Urheberrecht" (= author's right), which I think is much clearer.
If you author something, you have the sole copyright. In fact, in Germany you can't even waive your copyright away. However, you can grant licenses for the use of your work.
The difference between copyright and licenses is crucial! By licensing your work, you do not waive your copyright. You still remain the owner. If you publish your code under the GPL and you are the sole author, you can always relicense your code or issue commercial licenses under different terms.
> In general, it is kind of weird to want to copyright code. How do you patent a for-loop for example
There is a fundamental difference between copyright and patents! Patents require a novel technical contribution and they must be granted by a patent office.
If you author something, you have the sole copyright. In fact, in Germany you can't even waive your copyright away. However, you can grant licenses for the use of your work.
The difference between copyright and licenses is crucial! By licensing your work, you do not waive your copyright. You still remain the owner. If you publish your code under the GPL and you are the sole author, you can always relicense your code or issue commercial licenses under different terms.
> In general, it is kind of weird to want to copyright code. How do you patent a for-loop for example
There is a fundamental difference between copyright and patents! Patents require a novel technical contribution and they must be granted by a patent office.