This post is part of the Stack Based Virtual Machines series. In the previous part we have added many instructions to our virtual machine, such as jumps and local variables. It’s now time to discuss how we can use these instructions to implement an “if” statement, or a “while” loop. The complete unit tests implementing the code samples below can be on github. Implementing an IF Let start by implementing an if statement in our bytecode.