MKoD - D Programming Language

Basic Foreach_Reverse..Loop examples in D - code-name foreach_reverse.d

Basic Newbie Stuff Foreach_Reverse..Loop examples:

// foreach_reverse.d 
// foreach_reverse..loop examples in D - last tested with D v1.0
// To Compile: C:\dmd\MKoD_ex>dmd foreach_reverse.d
private import std.stdio;

int main()
{

    int[]  ix = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
    char[] sAlpha = "ABCDEFGHIJ";
    
    writefln( "foreach_reverse..loop 10 to 1 (with an index)" );
    foreach_reverse( int iy, int iz; ix )
    {
        writefln( "ix[ %d ]=%d == iz=%2d", iy, ix[ iy ], iz );
    }
    
    writefln();
    
    writefln( "foreach_reverse..loop 10 to 1 (without an index)" );
    foreach_reverse( int iz; ix )
    {
        writefln( "ix[]=%d", iz );
    }

    writefln();
    
    writefln( "foreach_reverse..loop J to A (with an index)" );
    foreach_reverse( int ix, dchar dc; sAlpha )
    {
        writefln( "sAlpha[ %d ]=%s == dc=%s", ix, sAlpha[ ix ], dc );
    }        
    return 0;
    
} // end int main()
C:\dmd\MKOD_ex>dmd foreach_reverse.d
C:\dmd\bin\..\..\dm\bin\link.exe foreach_reverse,,,user32+kernel32/noi;

C:\dmd\MKOD_ex>foreach_reverse
foreach_reverse..loop 10 to 1 (with an index)
ix[ 9 ]=10 == iz=10
ix[ 8 ]=9 == iz= 9
ix[ 7 ]=8 == iz= 8
ix[ 6 ]=7 == iz= 7
ix[ 5 ]=6 == iz= 6
ix[ 4 ]=5 == iz= 5
ix[ 3 ]=4 == iz= 4
ix[ 2 ]=3 == iz= 3
ix[ 1 ]=2 == iz= 2
ix[ 0 ]=1 == iz= 1

foreach_reverse..loop 10 to 1 (without an index)
ix[]=10
ix[]=9
ix[]=8
ix[]=7
ix[]=6
ix[]=5
ix[]=4
ix[]=3
ix[]=2
ix[]=1

foreach_reverse..loop J to A (with an index)
sAlpha[ 9 ]=J == dc=J
sAlpha[ 8 ]=I == dc=I
sAlpha[ 7 ]=H == dc=H
sAlpha[ 6 ]=G == dc=G
sAlpha[ 5 ]=F == dc=F
sAlpha[ 4 ]=E == dc=E
sAlpha[ 3 ]=D == dc=D
sAlpha[ 2 ]=C == dc=C
sAlpha[ 1 ]=B == dc=B
sAlpha[ 0 ]=A == dc=A

C:\dmd\MKOD_ex>

Mars: fourth Rock from the Sun.