From aebb906dfb81471157ec347e2b8129c03805d1f9 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Tue, 27 Aug 2024 05:08:16 +0000 Subject: [PATCH] Update Examples --- Examples.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Examples.md b/Examples.md index 696d247..c6a19f5 100644 --- a/Examples.md +++ b/Examples.md @@ -1358,11 +1358,37 @@ fn main ``` - +fn main() { + fn sum_odd_numbers(up_to: u32) -> u32 { + let mut acc = 0; + for i in 0..up_to { + let addition: u32 = match i%2 == 1 { + true => i, + false => continue, + }; + acc += addition; + } + acc + } + println!("Sum of odd numbers up to 9 (excluding): {}", sum_odd_numbers(9)); +} ``` ``` +fn main + fn sum_odd_numbers(up_to: u32) -> u32 + let mut acc = 0 + for i in 0..up_to + let addition: u32 = match i%2 == 1 + true => i + false => continue + acc += addition + acc + + println! + "Sum of odd numbers up to 9 (excluding): {}" + sum_odd_numbers 9 ```