MKoD - D Programming Language

Basic Goto LABEL..Loop examples in D - code-name gotoloop.d

Basic Newbie Stuff Goto LABEL..Loop examples:

// ** gotoloop.d 
// goto LABEL..loop examples in D - last tested with D v1.0
/+
 ' Please note that this is not a good programming practice in high-level 
 ' languages, and that it's here only to illustrate yet another method of 
 ' doing a loop. Plus, this is kind of a simple example of how a PC's 
 ' internal machine language would operate, with the help of innumerous 
 ' conditional "equal to" / "not equal to" actions that compare the values, 
 ' which in turn branch out into other areas of memory, using "Jumps (Gotos)."
 ' And since I've done some machine language on PCs and MainFrames in the 
 ' past, I guess that's why it came to mind when I started writing about 
 ' loops. :))
 +/
 // To Compile: C:\dmd\MKoD_ex>dmd gotoloop.d
private import std.stdio;

int main()
{
    int ix = 0;
    
    writefln( "goto LABEL..loop 1 to 10" );
    START_LOOP1:
    
        ix++;
        writefln("ix=%d", ix );     
    
    if(ix < 10 ) goto START_LOOP1;

    writefln();
    
    ix = 10;
    writefln( "goto LABEL..loop 10 to 1" );
    START_LOOP2:
     
        writefln("ix=%d", ix );     
        ix--;
        
    if(ix > 0 ) goto START_LOOP2;
    
    writefln();
    
    ix = 0;
    writefln( "goto LABEL..forever loop 1 to 10" );
    START_FOREVER:

        ix++;
        writefln("ix=%d", ix );     
    
        if(ix >= 10 ) goto EXIT;
        
    goto START_FOREVER;
    EXIT:
    
    return 0;
    
} // end int main()
C:\dmd\MKOD_ex>dmd gotoloop.d
C:\dmd\bin\..\..\dm\bin\link.exe gotoloop,,,user32+kernel32/noi;

C:\dmd\MKOD_ex>gotoloop
goto LABEL..loop 1 to 10
ix=1
ix=2
ix=3
ix=4
ix=5
ix=6
ix=7
ix=8
ix=9
ix=10

goto LABEL..loop 10 to 1
ix=10
ix=9
ix=8
ix=7
ix=6
ix=5
ix=4
ix=3
ix=2
ix=1

goto LABEL..forever loop 1 to 10
ix=1
ix=2
ix=3
ix=4
ix=5
ix=6
ix=7
ix=8
ix=9
ix=10

C:\dmd\MKOD_ex>
Mars: fourth Rock from the Sun.