Skip to content

Commit

Permalink
boolean to Boolean (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras authored Oct 17, 2024
1 parent 6bbc8f3 commit 988df1e
Show file tree
Hide file tree
Showing 28 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion concepts/arrays/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ foreach (char vowel in vowels)
A `for` loop does have some advantages over a `foreach` loop:

- You can start or stop at the index you want.
- You can use any (boolean) termination condition you want.
- You can use any (Boolean) termination condition you want.
- You can skip elements by customizing the incrementing of the loop variable.
- You can process collections from back to front by counting down.
- You can use `for` loops in scenarios that don't involve collections.
Expand Down
4 changes: 2 additions & 2 deletions concepts/booleans/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Booleans in C# are represented by the `bool` type, which values can be either `true` or `false`.

C# supports four [boolean operators][operators]: `!` (NOT), `&&` (AND), `||` (OR), and `^` (XOR). The `&&` and `||` operators use _short-circuit evaluation_, which means that the right-hand side of the operator is only evaluated when needed.
C# supports four [Boolean operators][operators]: `!` (NOT), `&&` (AND), `||` (OR), and `^` (XOR). The `&&` and `||` operators use _short-circuit evaluation_, which means that the right-hand side of the operator is only evaluated when needed.

```csharp
true || false // => true
Expand All @@ -11,7 +11,7 @@ true ^ false // => true
true ^ true // => false
```

The three boolean operators each have a different [_operator precedence_][precedence]. As a consequence, they are evaluated in this order: `not` first, `&&` second, `^` third, and finally `||`. If you want to 'escape' these rules, you can enclose a boolean expression in parentheses (`()`), as the parentheses have an even higher operator precedence.
The three Boolean operators each have a different [_operator precedence_][precedence]. As a consequence, they are evaluated in this order: `not` first, `&&` second, `^` third, and finally `||`. If you want to 'escape' these rules, you can enclose a Boolean expression in parentheses (`()`), as the parentheses have an even higher operator precedence.

```csharp
!true && false // => false
Expand Down
2 changes: 1 addition & 1 deletion concepts/booleans/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Booleans in C# are represented by the `bool` type, whose values can be either `true` or `false`.

C# supports three boolean operators: `!` (NOT), `&&` (AND), and `||` (OR).
C# supports three Boolean operators: `!` (NOT), `&&` (AND), and `||` (OR).
2 changes: 1 addition & 1 deletion concepts/const-readonly/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ By default, values in C# are _mutable_, that is they can change over time. To ma

The `const` modifier has some restrictions:

1. It can only be applied to "constant" types: strings, booleans and numbers.
1. It can only be applied to "constant" types: strings, Booleans and numbers.
1. The `const` value must be initialized immediately.

See [defining constants][defining-constants] for more information.
Expand Down
2 changes: 1 addition & 1 deletion concepts/const-readonly/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ By default, values in C# are _mutable_, that is they can change over time. To ma

The `const` modifier has some restrictions:

1. It can only be applied to "constant" types: strings, booleans and numbers.
1. It can only be applied to "constant" types: strings, Booleans and numbers.
1. The `const` value must be initialized immediately.

If your value is a non-constant type or you need to initialize the value in a constructor, `readonly` can be used to enforce immutability.
4 changes: 2 additions & 2 deletions concepts/enums/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum Priority : byte

## Convert to an Enum member

You should always consider using an enum whenever you want to model something like a boolean. Besides the aforementioned readability benefits, enums have another advantage over booleans: new values can always be added to an enum, whereas a boolean value will only ever be `true` or `false`. Using an enum is thus more future proof.
You should always consider using an enum whenever you want to model something like a Boolean. Besides the aforementioned readability benefits, enums have another advantage over Booleans: new values can always be added to an enum, whereas a Boolean value will only ever be `true` or `false`. Using an enum is thus more future proof.

```csharp
enum Status
Expand Down Expand Up @@ -71,7 +71,7 @@ Status status = (Status)Enum.Parse(typeof(Status), input);
// Inactive
```

To check if a name or a value exists in the enum, you can use [`Enum.TryParse`][enum tryparse] or [`Enum.IsDefined`][enum isdefined], both return a boolean indicating if the enum member exists:
To check if a name or a value exists in the enum, you can use [`Enum.TryParse`][enum tryparse] or [`Enum.IsDefined`][enum isdefined], both return a Boolean indicating if the enum member exists:

```csharp
bool doesExist = Enum.IsDefined(typeof(Status), "Inexistent");
Expand Down
2 changes: 1 addition & 1 deletion concepts/exception-filtering/about.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# About

`when` is the keyword in filtering exceptions. It is placed after the catch
statement and can take a boolean expression containing any values in scope at the time. They don't just have to be members of the exception itself. If the type of the exception matches and the expression evaluates to true then the block associated with that `catch` statement is executed otherwise the next `catch` statement, if any, is checked.
statement and can take a Boolean expression containing any values in scope at the time. They don't just have to be members of the exception itself. If the type of the exception matches and the expression evaluates to true then the block associated with that `catch` statement is executed otherwise the next `catch` statement, if any, is checked.

```csharp
try
Expand Down
2 changes: 1 addition & 1 deletion concepts/exception-filtering/introduction.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Introduction

`when` is the keyword in filtering exceptions. It is placed after the catch
statement and can take a boolean expression containing any values in scope at the time. If the expression evaluates to true then the block associated with that `catch` statement is executed otherwise the next `catch` statement, if any, is checked.
statement and can take a Boolean expression containing any values in scope at the time. If the expression evaluates to true then the block associated with that `catch` statement is executed otherwise the next `catch` statement, if any, is checked.

```csharp
try
Expand Down
2 changes: 1 addition & 1 deletion concepts/for-loops/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "For-loops allow for iteration over a specified range, with a boolean condition to indicate when to stop, and an increment to indicate how much to go up or down by.",
"blurb": "For-loops allow for iteration over a specified range, with a Boolean condition to indicate when to stop, and an increment to indicate how much to go up or down by.",
"authors": [
"ErikSchierboom"
],
Expand Down
2 changes: 1 addition & 1 deletion concepts/for-loops/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ foreach (char vowel in vowels)
A `for` loop does have some advantages over a `foreach` loop:

- You can start or stop at the index you want.
- You can use any (boolean) termination condition you want.
- You can use any (Boolean) termination condition you want.
- You can skip elements by customizing the incrementing of the loop variable.
- You can process collections from back to front by counting down.
- You can use `for` loops in scenarios that don't involve collections.
Expand Down
2 changes: 1 addition & 1 deletion concepts/foreach-loops/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ foreach (char vowel in vowels)
A `for` loop does have some advantages over a `foreach` loop:

- You can start or stop at the index you want.
- You can use any (boolean) termination condition you want.
- You can use any (Boolean) termination condition you want.
- You can skip elements by customizing the incrementing of the loop variable.
- You can process collections from back to front by counting down.
- You can use `for` loops in scenarios that don't involve collections.
Expand Down
2 changes: 1 addition & 1 deletion concepts/randomness/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ There are 3 patterns for implementing the last point:

- You can get the random number and manipulate it. In the case of the coding exercise this would consist of calling `Random.NextDouble()` and multiplying by 100. This [piece][random-use-case-array] discusses making random selections from an array.
- You can inherit from `System.Random` and override the `Sample()` method.
- You can encapsulate an instance of `System.Random` as a member of a class of your own, for example [to generate booleans][random-use-cases].
- You can encapsulate an instance of `System.Random` as a member of a class of your own, for example [to generate Booleans][random-use-cases].

The numbers generated by `Random` are not guaranteed to be unique.

Expand Down
2 changes: 1 addition & 1 deletion concepts/while-loops/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "A while loop continues looping until a boolean condition evaluates to false.",
"blurb": "A while loop continues looping until a Boolean condition evaluates to false.",
"authors": [
"ErikSchierboom"
],
Expand Down
2 changes: 1 addition & 1 deletion concepts/while-loops/about.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About

To repeatedly execute logic, one can use loops. One of the most common loop types in C# is the `while` loop, which keeps on looping until a boolean condition evaluates to `false`.
To repeatedly execute logic, one can use loops. One of the most common loop types in C# is the `while` loop, which keeps on looping until a Boolean condition evaluates to `false`.

```csharp
int x = 23;
Expand Down
4 changes: 2 additions & 2 deletions exercises/concept/annalyns-infiltration/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

## General

- There are three [boolean operators][operators] to work with boolean values.
- There are three [Boolean operators][operators] to work with Boolean values.
- Multiple operators can be combined in a single expression.

## 1. Check if a fast attack can be made

- The [boolean operators][operators] can also be applied to boolean parameters.
- The [Boolean operators][operators] can also be applied to Boolean parameters.

[operators]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/boolean-logical-operators
8 changes: 4 additions & 4 deletions exercises/concept/annalyns-infiltration/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ You have four tasks: to implement the logic for determining if the above actions

## 1. Check if a fast attack can be made

Implement the (_static_) `QuestLogic.CanFastAttack()` method that takes a boolean value that indicates if the knight is awake. This method returns `true` if a fast attack can be made based on the state of the knight. Otherwise, returns `false`:
Implement the (_static_) `QuestLogic.CanFastAttack()` method that takes a Boolean value that indicates if the knight is awake. This method returns `true` if a fast attack can be made based on the state of the knight. Otherwise, returns `false`:

```csharp
var knightIsAwake = true;
Expand All @@ -34,7 +34,7 @@ QuestLogic.CanFastAttack(knightIsAwake);

## 2. Check if the group can be spied upon

Implement the (_static_) `QuestLogic.CanSpy()` method that takes three boolean values, indicating if the knight, archer and the prisoner, respectively, are awake. The method returns `true` if the group can be spied upon, based on the state of the three characters. Otherwise, returns `false`:
Implement the (_static_) `QuestLogic.CanSpy()` method that takes three Boolean values, indicating if the knight, archer and the prisoner, respectively, are awake. The method returns `true` if the group can be spied upon, based on the state of the three characters. Otherwise, returns `false`:

```csharp
var knightIsAwake = false;
Expand All @@ -46,7 +46,7 @@ QuestLogic.CanSpy(knightIsAwake, archerIsAwake, prisonerIsAwake);

## 3. Check if the prisoner can be signalled

Implement the (_static_) `QuestLogic.CanSignalPrisoner()` method that takes two boolean values, indicating if the archer and the prisoner, respectively, are awake. The method returns `true` if the prisoner can be signalled, based on the state of the two characters. Otherwise, returns `false`:
Implement the (_static_) `QuestLogic.CanSignalPrisoner()` method that takes two Boolean values, indicating if the archer and the prisoner, respectively, are awake. The method returns `true` if the prisoner can be signalled, based on the state of the two characters. Otherwise, returns `false`:

```csharp
var archerIsAwake = false;
Expand All @@ -57,7 +57,7 @@ QuestLogic.CanSignalPrisoner(archerIsAwake, prisonerIsAwake);

## 4. Check if the prisoner can be freed

Implement the (_static_) `QuestLogic.CanFreePrisoner()` method that takes four boolean values. The first three parameters indicate if the knight, archer and the prisoner, respectively, are awake. The last parameter indicates if Annalyn's pet dog is present. The method returns `true` if the prisoner can be freed based on the state of the three characters and Annalyn's pet dog presence. Otherwise, it returns `false`:
Implement the (_static_) `QuestLogic.CanFreePrisoner()` method that takes four Boolean values. The first three parameters indicate if the knight, archer and the prisoner, respectively, are awake. The last parameter indicates if Annalyn's pet dog is present. The method returns `true` if the prisoner can be freed based on the state of the three characters and Annalyn's pet dog presence. Otherwise, it returns `false`:

```csharp
var knightIsAwake = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

Booleans in C# are represented by the `bool` type, which values can be either `true` or `false`.

C# supports three boolean operators: `!` (NOT), `&&` (AND), and `||` (OR).
C# supports three Boolean operators: `!` (NOT), `&&` (AND), and `||` (OR).
2 changes: 1 addition & 1 deletion exercises/concept/annalyns-infiltration/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"forked_from": [
"fsharp/annalyns-infiltration"
],
"blurb": "Learn about booleans while helping Annalyn rescue her friend."
"blurb": "Learn about Booleans while helping Annalyn rescue her friend."
}
8 changes: 4 additions & 4 deletions exercises/concept/annalyns-infiltration/.meta/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
## Learning objectives

- Know of the existence of the `bool` type and its two values.
- Know about boolean operators and how to build logical expressions with them.
- Know of the boolean operator precedence rules.
- Know about Boolean operators and how to build logical expressions with them.
- Know of the Boolean operator precedence rules.

## Out of scope

- Pattern matching on booleans.
- Pattern matching on Booleans.

## Concepts

- `booleans`: know of the existence of the `bool` type and its two values; know about boolean operators and how to build logical expressions with them; know of the boolean operator precedence rules.
- `booleans`: know of the existence of the `bool` type and its two values; know about Boolean operators and how to build logical expressions with them; know of the Boolean operator precedence rules.

## Prerequisites

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Exception Filtering

`when` is the keyword in filtering exceptions. It is placed after the catch
statement and can take a boolean expression containing any values in scope at the time. If the expression evaluates to true then the block associated with that `catch` statement is executed otherwise the next `catch` statement, if any, is checked.
statement and can take a Boolean expression containing any values in scope at the time. If the expression evaluates to true then the block associated with that `catch` statement is executed otherwise the next `catch` statement, if any, is checked.

```csharp
try
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/interest-is-interesting/.meta/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

This exercise's prerequisites Concepts are:

- `numbers`: define numbers and apply arithmetic and boolean logic to them.
- `numbers`: define numbers and apply arithmetic and Boolean logic to them.
- `if-statements`: conditionally execute code based on value of floating-point numbers.

[docs.microsoft.com-floating-point-numeric-types]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types
2 changes: 1 addition & 1 deletion exercises/concept/wizards-and-warriors/.meta/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- `classes`: know how to work with classes.
- `constructors`: know how to work with constructors.
- `strings`: know how to do basic string interpolation.
- `boolean`: know how to use boolean logic.
- `boolean`: know how to use Boolean logic.
- `if-statements`: know how to do conditional logic.

## Analyzer
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/leap/.approaches/boolean-chain/content.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Chain of boolean expressions
# Chain of Boolean expressions

```csharp
public static bool IsLeapYear(int year)
Expand All @@ -7,7 +7,7 @@ public static bool IsLeapYear(int year)
}
```

The first boolean expression uses the [remainder operator][remainder-operator] to check if the year is evenly divided by `4`.
The first Boolean expression uses the [remainder operator][remainder-operator] to check if the year is evenly divided by `4`.
- If the year is not evenly divisible by `4`, then the chain will "short circuit" due to the next operator being a [logical AND][logical-and] (`&&`), and will return `false`.
- If the year _is_ evenly divisible by `4`, then the year is checked to _not_ be evenly divisible by `100`.
- If the year is not evenly divisible by `100`, then the expression is `true` and the chain will "short-circuit" to return `true`,
Expand All @@ -22,7 +22,7 @@ since the next operator is a [logical OR][logical-or] (`||`).
| 1900 | true | false | false | false |


The chain of boolean expressions is efficient, as it proceeds from testing the most likely to least likely conditions.
The chain of Boolean expressions is efficient, as it proceeds from testing the most likely to least likely conditions.

## Shortening

Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/leap/.approaches/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"uuid": "54148cc8-e3bf-4981-95c9-cb584c658c76",
"slug": "boolean-chain",
"title": "Boolean chain",
"blurb": "Use a chain of boolean expressions.",
"blurb": "Use a chain of Boolean expressions.",
"authors": [
"bobahop"
],
Expand All @@ -26,7 +26,7 @@
"uuid": "eebe5a57-7e58-44c2-92e6-50f46f1251ac",
"slug": "ternary-operator",
"title": "Ternary operator",
"blurb": "Use a ternary operator of boolean expressions.",
"blurb": "Use a ternary operator of Boolean expressions.",
"authors": [
"bobahop"
],
Expand All @@ -44,7 +44,7 @@
"uuid": "cb7c88a6-49f3-4744-a3e8-fcc7acc0770d",
"slug": "switch-on-a-tuple",
"title": "switch on a tuple",
"blurb": "Use a switch on a tuple made from boolean expressions.",
"blurb": "Use a switch on a tuple made from Boolean expressions.",
"authors": [
"bobahop"
],
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/leap/.approaches/introduction.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Introduction

There are various idiomatic approaches to solve Leap.
You can use a chain of boolean expressions to test the conditions.
You can use a chain of Boolean expressions to test the conditions.
Or you can use a [ternary operator][ternary-operator].
Another approach you can use is a [switch][switch] on a [tuple][tuple].

Expand Down Expand Up @@ -59,7 +59,7 @@ Besides the aforementioned, idiomatic approaches, you could also solve the exerc

## Which approach to use?

- The chain of boolean expressions is most efficient, as it proceeds from the most likely to least likely conditions.
- The chain of Boolean expressions is most efficient, as it proceeds from the most likely to least likely conditions.
It has a maximum of three checks.
- The ternary operator has a maximum of only two checks, but it starts from a less likely condition.
- The `switch` on a `tuple` may be considered more "functional", but it is more verbose and may be considered less readable.
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/leap/.articles/performance/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ In this approach, we'll find out how to most efficiently calculate if a year is

The [approaches page][approaches] lists three idiomatic approaches to this exercise:

1. [Using the boolean chain][approach-boolean-chain]
1. [Using the Boolean chain][approach-boolean-chain]
2. [Using the ternary operator][approach-ternary-operator]
3. [Using `switch` in a `tuple`][approach-switch-on-a-tuple]

Expand Down
Loading

0 comments on commit 988df1e

Please sign in to comment.