Add examples for do..while and foreach loops in programming book
This commit is contained in:
20
main.typ
20
main.typ
@@ -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
|
||||
==== Wyjaśnienie
|
||||
|
Reference in New Issue
Block a user