Fix formatting and improve clarity in loop examples in programming book

This commit is contained in:
2025-09-27 11:57:49 +02:00
parent a01c63fbd4
commit 5b9d6a4cc6

View File

@@ -303,30 +303,31 @@ Jest jeszcze pętla `foreach`, która w róznych jezykach ma rózna składnię,
==== Przykład ==== Przykład
```cs ```cs
Console.WriteLine("Let's count to 10."); Console.WriteLine("Let's count to 10.");
for (int i = 0; i < 10; i++;) for (int i = 0; i < 10; i++)
{ {
Console.WriteLine(i + 1); Console.WriteLine(i + 1);
} }
bool shouldQuit = false; bool shouldQuit = false;
while (shouldQuit) { while (!shouldQuit)
Console.WriteLine("I will run until you type 'q'.") {
char response = Console.ReadLine(); Console.WriteLine("I will run until you type 'q'.");
if (response == 'q') { string response = Console.ReadLine();
shouldQuit = true; if (response == "q") {
} shouldQuit = true;
}
} }
string correctPin = "1234"; string correctPin = "1234";
string enteredPin = ""; string enteredPin = "";
do { do {
Console.Write("Please provide your PIN: "); Console.Write("Please provide your PIN: ");
enteredPin = Console.ReadLine(); enteredPin = Console.ReadLine();
if (enteredPin != correctPin) { if (enteredPin != correctPin) {
Console.WriteLine("Incorrect PIN. Try again"); Console.WriteLine("Incorrect PIN. Try again");
} }
} while (enteredPin != correctPin); } while (enteredPin != correctPin);
Console.WriteLine("Correct PIN! Access granted."); Console.WriteLine("Correct PIN! Access granted.");
@@ -334,10 +335,40 @@ Console.WriteLine("Correct PIN! Access granted.");
string[] shoppingList = new string[] { "bread", "chicken", "butter"}; string[] shoppingList = new string[] { "bread", "chicken", "butter"};
Console.WriteLine("Your shopping list:"); Console.WriteLine("Your shopping list:");
foreach (string product in shoppingList) { foreach (string product in shoppingList) {
Console.WriteLine($"- {product}"); Console.WriteLine($"- {product}");
} }
``` ```
==== Rezultat ==== Rezultat
Wynik działania powyższego kodu to:
```
Let's count to 10.
1
2
3
4
5
6
7
8
9
10
I will run until you type 'q'.
asdsd
I will run until you type 'q'.
cvcv
I will run until you type 'q'.
asas
I will run until you type 'q'.
q
Please provide your PIN: 123
Incorrect PIN. Try again
Please provide your PIN: 1234
Correct PIN! Access granted.
Your shopping list:
- bread
- chicken
- butter
```
==== Wyjaśnienie ==== Wyjaśnienie
==== Ćwiczenia ==== Ćwiczenia
=== Instrukcje skoku === Instrukcje skoku