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
- Because the initial value of
number
is 0, the logical expression of thewhile
loop isfalse
since the very beginning, and this is preventing from entering the loop body. A solution is to use an initial value that will allow thewhile
condition to betrue
at the beginning:int number = 3;
- 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-2025 by the D Language Foundation | Page generated by
Ddoc on Sun Aug 24 07:18:00 2025