Skipping or Stepping Through an Array?

DMon no at mail.com
Wed Oct 21 11:55:54 UTC 2020


What is the simplest way to output every nth element of an array?

I can do it using a for loop:
void main()
{
     int[5] a = [1,2,3,4,5];

     for (int i = 0 ; i <= 4 ; i += 2)
     {
         writeln(a[i]);
     }
}

Basically, I am wondering if I missed something.


More information about the Digitalmars-d-learn mailing list