www.meestuf.com
-----------------------------------------------------------------------------------------------------
1. Create a new console project.
2. Edit the Program.cs file as shown below.
static void Main(string[] args)
{
string favoritePet = "Dog";
Console.WriteLine("My favorite pet is a " + favoritePet);
if (favoritePet == "Cat")
{
Console.WriteLine("Then it says: Meow!");
}
else
{
Console.WriteLine("Then it says: Woof!");
}
Console.WriteLine("Press any key to continue....");
Console.ReadLine();
}
4. Thank you.
The if-else statement is used to add condition to a piece of code. Its syntax is:
if(
//code
else
// any other code
condition – could be anything that would result in a true or false. "if" only runs the code inside its braces when the condition is true. If the condition fails or evaluates to false the code under the else will get executed.
-----------------------------------------------------------------------------------------------------
Manage and share your stuff for FREE!
www.meestuf.com
-----------------------------------------------------------------------------------------------------
Manage and share your stuff for FREE!
www.meestuf.com
No comments:
Post a Comment