Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Utmaning: If-Villkor | Styrstrukturer
C#-Grunder

bookUtmaning: If-Villkor

Skriv en if-sats som kontrollerar om variabeln x ligger inom intervallet 40 till 70 (inklusive 40 och 70). Använd operatorerna <= för jämförelse. Om villkoret är sant ska det skriva ut "In Range".

main.cs

main.cs

copy
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 } } }

Syntaxen för en if-sats är: if(condition) { /* code to execute */ }

main.cs

main.cs

copy
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 } } }

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 6

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Suggested prompts:

Can you show me an example using a specific value for x?

Can you explain how the if-condition works in this case?

What happens if x is outside the range?

Awesome!

Completion rate improved to 1.59

bookUtmaning: If-Villkor

Svep för att visa menyn

Skriv en if-sats som kontrollerar om variabeln x ligger inom intervallet 40 till 70 (inklusive 40 och 70). Använd operatorerna <= för jämförelse. Om villkoret är sant ska det skriva ut "In Range".

main.cs

main.cs

copy
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 } } }

Syntaxen för en if-sats är: if(condition) { /* code to execute */ }

main.cs

main.cs

copy
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 } } }

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 6
some-alt