home comics writing pictures archive about

2018-01-20 - In IL: Loop Instructions

In IL

This post will be really simple because there are no IL loop instructions. As we shall see loops in IL are implemented using branching instructions just like the conditional statements we saw previously. The main difference is that conditionals tend to jump forward while loops tend to jump backwards so that instructions can be re-ran.

So the question is why isn't there any loop instructions? Well let's think about what these loop instructions would need to do. There is a large variety of programing languages out there and those languages have very different ideas about how they want their loops to work. In order for the IL loop instructions to be useful they would need to meet the majority of these scenarios which would require a large number of very complex looping instructions. So instead IL provides simple branching instructions that can be combined to create complex looping statements. Keeping IL simple and providing more power to languages that want to target IL.

Next time we will look at the simple while loop.

Comments: