Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Haaste: If-ehto | Ohjausrakenteet
C# Perusteet

bookHaaste: If-ehto

Kirjoita if-ehto, joka tarkistaa, onko muuttuja x välillä 40–70 (mukaan lukien 40 ja 70). Käytä vertailuun <=-operaattoreita. Jos ehto on tosi, tulostetaan "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 } } }

If-ehdon syntaksi on: 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 } } }

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 6

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

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

bookHaaste: If-ehto

Pyyhkäise näyttääksesi valikon

Kirjoita if-ehto, joka tarkistaa, onko muuttuja x välillä 40–70 (mukaan lukien 40 ja 70). Käytä vertailuun <=-operaattoreita. Jos ehto on tosi, tulostetaan "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 } } }

If-ehdon syntaksi on: 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 } } }

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 6
some-alt