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
```cs
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;
while (shouldQuit) {
Console.WriteLine("I will run until you type 'q'.")
char response = Console.ReadLine();
if (response == 'q') {
shouldQuit = true;
}
while (!shouldQuit)
{
Console.WriteLine("I will run until you type 'q'.");
string response = Console.ReadLine();
if (response == "q") {
shouldQuit = true;
}
}
string correctPin = "1234";
string enteredPin = "";
do {
Console.Write("Please provide your PIN: ");
enteredPin = Console.ReadLine();
Console.Write("Please provide your PIN: ");
enteredPin = Console.ReadLine();
if (enteredPin != correctPin) {
Console.WriteLine("Incorrect PIN. Try again");
}
if (enteredPin != correctPin) {
Console.WriteLine("Incorrect PIN. Try again");
}
} while (enteredPin != correctPin);
Console.WriteLine("Correct PIN! Access granted.");
@@ -334,10 +335,40 @@ 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}");
Console.WriteLine($"- {product}");
}
```
==== 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
==== Ćwiczenia
=== Instrukcje skoku