Respuesta :
Answer:
A conditional statement instructs a system to do action based on whether a condition is true or false. This is frequently expressed as an if-then or if-then-else expression. A conditional statement is applied to predicate choices on circumstances. When there is no condition around the instructions, they run sequentially. If you add a condition to a block of statements, the execution flow may alter depend on the outcome of the condition. It is also known as a one-way selection statement because we utilize the if condition, provide the argument, and if the argument is passed, the relevant function is performed; else, nothing happens.
Examples of conditional statements:
1) int time = 20;
if (time < 16) {
System.out.println("Have a good day.");
} else {
System.out.println(" Enjoy your evening.");
}
2) using namespace Conditional;
static void Main(string[] args)
{
// This method determines what a user should do for the day based on the weather condition
public void Weather(string myWeather)
{
// 1st condition
if (myWeather == "Sun")
{
// Decision
Console.WriteLine("Go to the beach");
}
// 2nd condition
else if (myWeather == "Rain")
{
Console.WriteLine("Go to the library")
}
// 3rd condition
else if (myWeather == "Cloudy")
{
Console.WriteLine("Go to the park")
}
else
{
//otherwise
Console.WriteLine("Rest at home")
}
}
}