Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
Slices and Other Array Features Solution
Slices and Other Array Features Dersi Problem Çözümleri
Iterating over elements by consuming a slice from the beginning is an interesting concept. This method is also the basis of Phobos ranges that we will see in a later chapter.
import std.stdio; void main() { double[] array = [ 1, 20, 2, 30, 7, 11 ]; double[] slice = array; // Start with a slice that // provides access to all of // the elements of the array while (slice.length) { // As long as there is at least // one element in that slice if (slice[0] > 10) { // Always use the first element slice[0] /= 2; // in the expressions } slice = slice[1 .. $]; // Shorten the slice from the // beginning } writeln(array); // The actual elements are // changed }
Copyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Sun Aug 24 07:18:00 2025