🕵️ SicherheitslückenCVE-2024-33668 | Zammad up to 6.2.x Upload Cache excessive authentication(17.09.2026 um 02:15 Uhr)
🕵️ SicherheitslückenCVE-2024-33668 | Zammad up to 6.2.x Upload Cache excessive authentication(17.09.2026 um 02:15 Uhr)
🔧 Programmierung 🕛 vor 1 Jahr 3 Min Lesezeit
0

Part 4: Control Flow in C#

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Control flow in a program determines the order in which instructions are executed. In C#, these decisions and repetitions are managed with specific structures that allow you to create dynamic and flexible programs. In this lesson, we will explore the main control flow structures: decisions and loops.






1. Decision Structures



Decision structures allow the program to execute different blocks of code depending on a condition. The most common ones in C# are if, else if, and else.






1.1 if



The if block evaluates a condition and executes the code inside the block if the condition is true.




CODE
int number = 10;
if (number > 5)
{
Console.WriteLine("The number is greater than 5.");
}









1.2 else if



This is used to evaluate additional conditions if the initial condition is not met.




CODE
int number = 5;
if (number > 10)
{
Console.WriteLine("The number is greater than 10.");
}
else if (number == 5)
{
Console.WriteLine("The number is equal to 5.");
}









1.3 else



The else block is executed if none of the previous conditions are met.




CODE
int number = 3;
if (number > 10)
{
Console.WriteLine("The number is greater than 10.");
}
else if (number == 5)
{
Console.WriteLine("The number is equal to 5.");
}
else
{
Console.WriteLine("The number is not greater than 10 nor equal to 5.");
}









2. Loop Structures



Loops or repetition structures allow you to execute a block of code multiple times, making repetitive tasks easier.






2.1 for



The for loop is ideal when you know the exact number of iterations.




CODE
for (int i = 0; i < 5; i++)
{
Console.WriteLine($"Iteration {i}");
}









2.2 while



The while loop executes the code as long as the condition is true.




CODE
int counter = 0;
while (counter < 5)
{
Console.WriteLine($"Counter: {counter}");
counter++;
}









2.3 do-while



Similar to while, but it ensures that the block of code is executed at least once.




CODE
int counter = 0;
do
{
Console.WriteLine($"Counter: {counter}");
counter++;
} while (counter < 5);









2.4 foreach



This is used to iterate through collections such as arrays or lists in a simple way.




CODE
int[] numbers = {1, 2, 3, 4, 5};
foreach (int number in numbers)
{
Console.WriteLine(number);
}









3. Practical Exercises






3.1 Calculate the Factorial of a Number



The factorial of a positive integer n is the product of all positive integers less than or equal to n.




CODE
int number = 5;
int factorial = 1;
for (int i = 1; i <= number; i++)
{
factorial *= i;
}
Console.WriteLine($"The factorial of {number} is {factorial}.");









3.2 Consecutive Sums



Calculate the sum of the first n natural numbers.




CODE
int n = 10;
int sum = 0;
for (int i = 1; i <= n; i++)
{
sum += i;
}
Console.WriteLine($"The sum of the first {n} numbers is {sum}.");









3.3 Check if a Number is Prime



A prime number is one that is only divisible by 1 and itself.




CODE
int number = 7;
bool isPrime = true;
for (int i = 2; i < number; i++)
{
if (number % i == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
Console.WriteLine($"{number} is a prime number.");
}
else
{
Console.WriteLine($"{number} is not a prime number.");
}


Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
CVE-2020-20212 | MikroTik RouterOS 6.44.5 /nova/bin/console null pointer dereference
2 Quellen
CVE-2017-17537 | MikroTik RouterBOARD 6.39.2/6.40.5 TCP Service 53 input validation (EDB-43200 / ID 860320)
2 Quellen
CVE-2023-27169 | Xpand IT Write-Back Manager 2.3.1 hash predictable salt (EUVD-2023-30949)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Part 4: Control Flow in C#

Thematisch verwandte Begriffe: Part, Control, Flow · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...