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.

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!");
    }