2018-09-01 - In IL: Print the Alphabet (Do Until)
In IL
- Part 1 - Introduction
- Part 2 - Variables and Types
- Part 3 - Variables in Visual Basic .NET
- Part 4 - Instructions and the Stack
- Part 5 - Volume of a Cylinder (Operations)
- Part 6 - Branching Instructions
- Part 7 - Largest of Two Numbers (if-else)
- Part 8 - Largest of Three Numbers (If-ElseIf-Else)
- Part 9 - Switch instruction
- Part 10 - Grade Analyser (switch)
- Part 11 - Prize Calculator (switch-2)
- Part 12 - VB Grade Analyser (Select)
- Part 13 - Loop Instructions
- Part 14 - Print the Alphabet (while)
- Part 15 - Print the Alphabet (do while, for)
- Part 16 - Print the Alphabet (Do Until)
- Part 17 - Print the Alphabet (break, continue)
- Part 18 - Array Instructions
- Part 19 - Summing Arrays
- Part 20 - Other Instructions
- Part 21 - Assemblies
- Part 22 - Class Definitions
- Part 23 - C# Classes and Structs
- Part 24 - VB Classes, Modules and Structures
- Part 25 - Field Definitions
- Part 26 - Field Declarations
In the last few parts we've been looking at C# loops, today we're going to look at a couple Visual Basic .NET loops. VB has a lot of the same loops as C#, with some syntax differences, but the Do Until and the Do ... Until loops are VB only. The Do Until loop is similar to the while loop except that instead of looping while the condition is true it loops until the condition is true, hence the Until keyword.
One thing you might notice about this code is the strange way the character is incremented. This is because Visual Basic .NET has different rules about implicitly converting characters to integers which requires us to explicitly convert the value to an integer, increment it, and then convert it back to being a character. Now let's compile it and see how that looks.
Except for the different instructions to increment the character this looks almost identical to the while loop version we saw previously.
Now let's look at the other version of the Do Until loop which puts the Until after the loop similar to the do ... while loop.
and if we compile that we get.
Again that looks very much like the do ... while loop we saw last time. The language gives you two ways of doing something but the compiler converts them into a single way by reversing your logic. The Until syntax is simply a tool for you to better describe your program's intentions using words.
Next time we will look at continue and break statements.
Comments: