The while Loop Solutions - 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 GitHub 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.

# The while Loop Solutions

#### The `while` Loop Dersi Problem Çözümleri

1. Because the initial value of `number` is 0, the logical expression of the `while` loop is `false` since the very beginning, and this is preventing from entering the loop body. A solution is to use an initial value that will allow the `while` condition to be `true` at the beginning:

           int number = 3;

2. All of the variables in the following program are default initialized to 0. This allows entering both of the loops at least once:

       import std.stdio;

       void main() {
           int secretNumber;

           while ((secretNumber < 1) || (secretNumber > 10)) {
               write("Please enter a number between 1 and 10: ");
               readf(" %s", &secretNumber);
           }

           int guess;

           while (guess != secretNumber) {
               write("Guess the secret number: ");
               readf(" %s", &guess);
           }

           writeln("That is correct!");
       }

Copyright © 1999-2026 by the D Language Foundation | Page generated by Ddoc on Wed Aug 19 13:28:52 2026