Skip to content

Commit

Permalink
Use dbg! instead of println! in Day 1 mng session.
Browse files Browse the repository at this point in the history
Part of google#2478.
  • Loading branch information
Eric Githinji committed Feb 21, 2025
1 parent 63cc474 commit 372b587
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/control-flow-basics/blocks-and-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ fn main() {
let z = 13;
let x = {
let y = 10;
println!("y: {y}");
dbg!(y);
z - y
};
println!("x: {x}");
// println!("y: {y}");
dbg!(x);
// dbg!(y);
}
```

Expand All @@ -27,6 +27,8 @@ A variable's scope is limited to the enclosing block.

<details>

- You can explain that dbg! is a Rust macro that prints and returns the value of a given expression for quick and dirty debugging.

- You can show how the value of the block changes by changing the last line in
the block. For instance, adding/removing a semicolon or using a `return`.

Expand Down
2 changes: 1 addition & 1 deletion src/control-flow-basics/break-continue.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
if i % 2 == 0 {
continue;
}
println!("{}", i);
dbg!(i);
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion src/control-flow-basics/break-continue/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
}
}
}
print!("elements searched: {elements_searched}");
dbg!(elements_searched);
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/control-flow-basics/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn gcd(a: u32, b: u32) -> u32 {
}
fn main() {
println!("gcd: {}", gcd(143, 52));
dbg!(gcd(143, 52));
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/control-flow-basics/loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ fn main() {
while x >= 10 {
x = x / 2;
}
println!("Final x: {x}");
dbg!(x);
}
```
4 changes: 2 additions & 2 deletions src/control-flow-basics/loops/for.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ ranges of values or the items in a collection:
```rust,editable
fn main() {
for x in 1..5 {
println!("x: {x}");
dbg!(x);
}
for elem in [2, 4, 8, 16, 32] {
println!("elem: {elem}");
dbg!(elem);
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion src/control-flow-basics/loops/loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
let mut i = 0;
loop {
i += 1;
println!("{i}");
dbg!(i);
if i > 100 {
break;
}
Expand Down

0 comments on commit 372b587

Please sign in to comment.