From 49969a1b5ff1a6339cab4bd17755a1bb9fb62869 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sun, 19 Mar 2023 14:03:57 +0200 Subject: [PATCH] Update Lesson 1 Task 3 --- Lesson_1/Task_3/Program.cs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Lesson_1/Task_3/Program.cs b/Lesson_1/Task_3/Program.cs index d6818d8..94cd822 100644 --- a/Lesson_1/Task_3/Program.cs +++ b/Lesson_1/Task_3/Program.cs @@ -9,27 +9,31 @@ List numbers = new List(); for (int i = 0; i < 10; i++) { - int newNumber; + int newNumber; - do - { - Console.Write($"Enter number {i + 1}: "); - } while (!int.TryParse(Console.ReadLine(), out newNumber)); + while (true) + { + Console.Write($"Enter number {i + 1}: "); + if (int.TryParse(Console.ReadLine(), out newNumber)) + break; + } - numbers.Add(newNumber); + numbers.Add(newNumber); } -do +while (true) { - Console.Write("Enter a number to duplicate: "); -} while (!int.TryParse(Console.ReadLine(), out duplicate)); + Console.Write($"Enter number to duplicate: "); + if (int.TryParse(Console.ReadLine(), out duplicate)) + break; +} for (int i = 0; i < numbers.Count; i++) { - if (numbers[i] == duplicate) - { - numbers.Insert(i, duplicate); - i++; - } + if (numbers[i] == duplicate) + { + numbers.Insert(i, duplicate); + i++; + } } Console.WriteLine(String.Join(", ", numbers));