Logical Expressions 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 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.

# Logical Expressions Solutions

#### Logical Expressions Dersi Problem Çözümleri

1. Because the compiler recognizes `10 < value` already as an expression, it expects a comma after it to accept it as a legal argument to `writeln`. Using parentheses around the whole expression would not work either, because this time a closing parenthesis would be expected after the same expression.
2. Grouping the expression as `(10 < value) < 20` removes the compilation error, because in this case first `10 < value` is evaluated and then its result is used with `< 20`.

   We know that the value of a logical expression like `10 < value` is either `false` or `true`. `false` and `true` take part in integer expressions as 0 and 1, respectively. (We will see automatic type conversions in a later chapter.) As a result, the whole expression is the equivalent of either `0 < 20` or `1 < 20`, both of which evaluate to `true`.

3. The expression "greater than the lower value and less than the upper value" can be coded as follows:

           writeln("Is between: ", (value > 10) && (value < 20));

4. "There is a bicycle for everyone" can be coded as `personCount <= bicycleCount` or `bicycleCount >= personCount`. The rest of the logical expression can directly be translated to D from the exercise:

           writeln("We are going to the beach: ",
                   ((distance < 10) && (bicycleCount >= personCount))
                   ||
                   ((personCount <= 5) && existsCar && existsLicense)
                   );

   Note the placement of the `||` operator to help with readability by separating the two main conditions.

Copyright © 1999-2026 by the D Language Foundation | Page generated by Ddoc on Wed Aug 5 15:38:52 2026