From e3248fec779f99522dbbbd5f32a7f14494193060 Mon Sep 17 00:00:00 2001 From: Eddington Chamunorwa Date: Thu, 28 Jul 2022 11:21:54 +0200 Subject: [PATCH 1/2] Improve the way of iterating a list object. A much more improved way of iterating list elements. --- Corrections/Correction_Ruby.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Corrections/Correction_Ruby.rb b/Corrections/Correction_Ruby.rb index fd1e68d..e65cd2a 100644 --- a/Corrections/Correction_Ruby.rb +++ b/Corrections/Correction_Ruby.rb @@ -43,8 +43,9 @@ # FIXME: For-loop - shoppingList # Create a for loop that iterate through "shoppingList" and prints each element. -for i in 0..nb_of_elts - 1 - puts shoppingList[i]; +shoppingList.each do + |element| + puts element end # FIXME: Foreach-loop From aa287291457be00ce7c76751c18d0e6202d97bb8 Mon Sep 17 00:00:00 2001 From: Eddington Chamunorwa Date: Thu, 28 Jul 2022 11:28:19 +0200 Subject: [PATCH 2/2] Improve C list, iterator. C: Improving the iterator, no need to know the explicit size, instead make the end. --- Corrections/Correction_C.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Corrections/Correction_C.c b/Corrections/Correction_C.c index d5643f1..cd3bf48 100644 --- a/Corrections/Correction_C.c +++ b/Corrections/Correction_C.c @@ -56,7 +56,7 @@ int main() // FIXME: Array // create a new string array called "shoppingList", with three elements of your choice. Create an int variable containing the number of // elements in "shoppingList" (using a function of the array/using the array) - char *shoppingList[3] = {"milk", "a Chevy Camaro", "a life"}; + char *shoppingList[3] = {"milk", "a Chevy Camaro", "a life", NULL}; const int nbOfElements = numberOfElements(shoppingList); // FIXME: For-loop - Integer @@ -67,8 +67,14 @@ int main() // FIXME: For-loop - shoppingList // Create a for loop that iterate through "shoppingList" and prints each element with "You have to buy (elemt)". - for (int j = 0; j