Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dbg! instead of println! in Day 1 mng session #2652

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 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,9 @@ 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