Slices and Other Array Features Solution - D Programming Language
Description: D Programming Language
Keywords: D programming language

Menu

- Learn
- Documentation
  - Language Reference
  - Library Reference
  - Command-line Reference
  - Feature Overview
  - Articles
- Downloads
- Packages
- Community
  - Blog
  - Orgs using D
  - Twitter
  - Calendar
  - Discord (community-run)
  - Forums
  - IRC
  - Wiki
  - Issues
  - Contributing
  - Contributors
  - Foundation
  - Security Team
  - Donate
  - Sponsors
- Resources
  - Tour
  - Books
  - Tutorials
  - Tools
  - Editors
  - IDEs
  - run.dlang.io
  - Visual D
  - Acknowledgments
  - D Style
  - Glossary
  - Sitemap

Search
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-2026 by the D Language Foundation | Page generated by Ddoc on Mon Aug 17 18:57:14 2026