From 808b8f58b061777a7f7eb61212b204643e52c58f Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 16 Oct 2024 17:27:46 +0200 Subject: [PATCH] Update the code to use a `for` loop --- loops/src/main.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/loops/src/main.rs b/loops/src/main.rs index 38fd301..b44e6b7 100644 --- a/loops/src/main.rs +++ b/loops/src/main.rs @@ -1,10 +1,7 @@ fn main() { let a = [10, 20, 30, 40, 50]; - let mut index = 0; - while index < 5 { - println!("the value is: {}", a[index]); - - index += 1; + for element in a { + println!("the value is: {element}"); } }