Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Herausforderung: If-Bedingung | Kontrollstrukturen
C# Grundlagen

book
Herausforderung: If-Bedingung

Schreiben Sie eine if-Bedingung, die überprüft, ob die Variable x im Bereich von 40 bis 70 liegt (einschließlich 40 und 70). Verwenden Sie die <= Operatoren für Vergleich. Wenn die Bedingung wahr ist, sollte sie "In Range" ausgeben.

cs

main

copy
using System;

namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
int x = 55;

// Write code below this line

// Write code above this line
}
}
}
12345678910111213141516
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int x = 55; // Write code below this line // Write code above this line } } }

Die Syntax einer if-Bedingung ist: if(condition) { /* code to execute */ }

cs

main

copy
using System;

namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
int x = 55;

// Write code below this line
if (40 <= x && x <= 70)
{
Console.WriteLine("In Range");
}
// Write code above this line

}
}
}
1234567891011121314151617181920
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int x = 55; // Write code below this line if (40 <= x && x <= 70) { Console.WriteLine("In Range"); } // Write code above this line } } }

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 6
some-alt