Add examples for do..while and foreach loops in programming book

This commit is contained in:
2025-09-27 11:51:28 +02:00
parent 9d9764e296
commit a01c63fbd4

View File

@@ -317,7 +317,25 @@ while (shouldQuit) {
} }
} }
//TODO: do..while example & foreach example string correctPin = "1234";
string enteredPin = "";
do {
Console.Write("Please provide your PIN: ");
enteredPin = Console.ReadLine();
if (enteredPin != correctPin) {
Console.WriteLine("Incorrect PIN. Try again");
}
} while (enteredPin != correctPin);
Console.WriteLine("Correct PIN! Access granted.");
string[] shoppingList = new string[] { "bread", "chicken", "butter"};
Console.WriteLine("Your shopping list:");
foreach (string product in shoppingList) {
Console.WriteLine($"- {product}");
}
``` ```
==== Rezultat ==== Rezultat
==== Wyjaśnienie ==== Wyjaśnienie