Control Flow

mail@pastecode.io avatar
unknown
csharp
2 months ago
1.2 kB
37
Indexable
Never
// If, Else, Else If

int age = 18;

if (age < 18 && age > 0)
{
    Console.WriteLine("You are a Minor");
}

else if (age >= 18 && age < 60)
{
    Console.WriteLine("You are an Adult");
}

else if (age >= 60)
{
    Console.WriteLine("You are a Senior Citizen");
}

else
{
    Console.WriteLine("Invalid Age");
}

// string name = "Jehu";

// if (name == "Jehu")
// {
//     Console.WriteLine();
// }

// // Switch Case
char grade = 'A';

switch (grade)
{
    case 'A':
        Console.WriteLine("1.00");
        break;
    case 'B':
        Console.WriteLine("2.00");
        break;
    case 'C':
        Console.WriteLine("3.00");
        break;
    default:
        Console.WriteLine("Bagsak");
        break;
}

// While
bool loading = true;

while (loading == true)
{
    Console.WriteLine("Retry ");
}

loading = false;

// counter
int counter = 1;

while (count <= 10)
{
    Console.WriteLine("Count: " + count);
    count++;
}

// For
//for (initialization; condition; increment/decrement)

for (int column = 0; column < 10; column++)
{
    for (int row = 0; row < 10; row++)
    {
        Console.Write("#");
    }
    Console.WriteLine();
}
Leave a Comment