+ 1

Can you add couple of if else statements?

25th Oct 2016, 2:25 PM
UnknownCayon
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.
27th Oct 2016, 7:55 PM
MohammadReza Dehnashi
MohammadReza Dehnashi - avatar
+ 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! ^^
26th Oct 2016, 2:29 AM
Hanike T.
Hanike T. - avatar
+ 2
yes u can add couple of if else statements...it won't show an error
1st Jan 2017, 5:36 PM
MEDHIR
MEDHIR - avatar
+ 1
Yes. As many as you want.
25th Oct 2016, 6:05 PM
Sumita Das
Sumita Das - avatar
+ 1
Yes, like "if (condition) else{ if (condition) else}"
26th Oct 2016, 12:33 AM
violet
0
yes
25th Oct 2016, 3:35 PM
Idhayavarman Rajan
Idhayavarman Rajan - avatar
0
if(cond){ if(cond2){ } else { } } else { if(cond3){ } } multiple statements are allowed
26th Oct 2016, 2:23 AM
Carlos Alberto Carvajal
0
yes
14th Nov 2016, 10:53 AM
Taha Elbir
Taha Elbir - avatar
0
yes.. we can use nested if
27th Nov 2016, 5:29 AM
sowmith pokala
sowmith pokala - avatar
0
yeah.you can add multiple if-else statemnents as much as you want.
1st Jan 2017, 12:43 AM
DEBI PRASAD RATHA
DEBI PRASAD RATHA - avatar
0
yes you can use as many else if but instead of using many of those try to use recursion
1st Jan 2017, 6:39 AM
Harsh
0
yes
1st Jan 2017, 4:32 PM
grizly
grizly - avatar
0
Yes, u can use nested if else statement
9th Sep 2019, 10:14 AM
Suraj Gupta
Suraj Gupta - avatar
- 1
either you can use de switch statement
25th Oct 2016, 3:07 PM
∆Gusta∆
- 1
yes you can
25th Oct 2016, 3:50 PM
Syed Taha Ahmed Zaidi
Syed Taha Ahmed Zaidi - avatar