Decision making : if-else,else if ladder Errors
Mistake 1 : Assignment Operator & Comparison Operators
- Assignment Operator (=) is used for assigning value to variable
- Comparison Operator (==) checks whether LHS and RHS entries are same or not
- In if statement Use "==" instead of "="
if(var = 10)
{
//Statement 1
//Statement 2
//Statement 3
//Statement n
}instead of write this .....if(var == 10)
{
//Statement 1
//Statement 2
//Statement 3
//Statement n
}Mistake 2 : Use of Semicolon
- Using Semicolon at the end of if statement
- Don't Use Semicolon.
if(var == 10);
Mistake 3 : Else without using if
- Error Message : Misplaced Else
- Else must have corresponding if
Statement1 ;
Statement2 ;
..
else
{
Statement 3;
Statement 4;
.
.
}
}
Mistake 4 : Opening and Closing Braces
- If multiple Statements within if must be wrapped in Pair of braces.
- Error Message : Misplaced else
- Statement1 and statement2 must be wrapped inside if
- Here only Statement1 is the part of if
Statement1 ;
if(condition)
Statement1 ;
Statement2 ;
else
{
Statement 3;
Statement 4;
}
Write it as -if(condition)
{
Statement1 ;
Statement2 ;
}
else
{
Statement 3;
Statement 4;
}
0 comments
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email