I would keep goto-label-if
. That is what the compiler turns everything into anyway. The most basic form of flow control is conditional branching and that is done with the branch
/jump
opcodes.
I have examples of loop conversions on the answer to another question.
... this C# code ...
static void @ifgoto(bool input)
{
label:
if (input)
goto label;
}
static void @while(bool input)
{
while (input) ;
}
static void @for(bool input)
{
for (; input; ) ;
}
... Compiles to this ...
.method private hidebysig static void ifgoto(bool input) cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: brtrue.s L_0000
L_0003: ret
}
.method private hidebysig static void while(bool input) cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: brtrue.s L_0000
L_0003: ret
}
.method private hidebysig static void for(bool input) cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: brtrue.s L_0000
L_0003: ret
}
.. To explain this more ...
// load input
L_0000: ldarg.0
// if input is true branch to L_000
L_0001: brtrue.s L_0000
// else return
L_0003: ret