Inclusion of `computer code` in a thesis
You should add source codes scarcely and when it is interesting to add the code. Loop does not sound one of the interesting headings. In those cases you should include source code as figures and discuss them in your text. 

in other cases, you can give complete source codes in appendix or in a CD/DVD as an attachment.