+ 1
Can you add couple of if else statements?
16 Réponses
+ 3
Example
In the following example, you enter a character from the keyboard, and the program uses a nested if statement to determine whether the input character is an alphabetic character. If the input character is an alphabetic character, the program checks whether the input character is lowercase or uppercase. A message appears for each case.
C#
Console.Write("Enter a character: ");
char c = (char)Console.Read();
if (Char.IsLetter(c))
{
if (Char.IsLower(c))
{
Console.WriteLine("The character is lowercase.");
}
else
{
Console.WriteLine("The character is uppercase.");
}
}
else
{
Console.WriteLine("The character isn't an alphabetic character.");
}
//Sample Output:
//Enter a character: 2
//The character isn't an alphabetic character.
//Enter a character: A
//The character is uppercase.
//Enter a character: h
//The character is lowercase.
+ 2
Technically you can use multiple layers of it, but it's not a good practice if it's over 2.
Instead of using multiple if-elses, rethink your problem and check if you can't use a recursion method instead or if other conditionals wouldn't fit your problem better! ^^
+ 2
yes u can add couple of if else statements...it won't show an error
+ 1
Yes.
As many as you want.
+ 1
Yes, like "if (condition)
else{ if (condition)
else}"
0
yes
0
if(cond){ if(cond2){ } else { } } else { if(cond3){ } } multiple statements are allowed
0
yes
0
yes.. we can use nested if
0
yeah.you can add multiple if-else statemnents as much as you want.
0
yes you can use as many else if but instead of using many of those try to use recursion
0
yes
0
Yes, u can use nested if else statement
- 1
either you can use de switch statement
- 1
yes you can