Explain If…else statements
Answers
Answered by
0
Answer is in the attachment
Attachments:
Answered by
2
If and else statements are used to execute code blocks if the specified condition is true.
- They are called conditional statements as they are used to perform different tasks on the basis of the conditions.
- Use if to execute the code block, if a specified condition is true, otherwise else can be used additionally to evaluate a different outcome if the the statement is wrong.
- Else if can be used when we want to try out a different set of code statements for a different variant of outcome upon the execution of that code block.
for example:
int a=5;
int b=2;
int c=10;
if (a<b)
{ a=a+b;
}
else if ( a<c)
{a=a+c;
}
else
{
cout<<"a is the largest";
}
Here, the code will reach the else statement block only if the above ones are incorrect.
Similar questions
Math,
5 months ago
Math,
5 months ago
Computer Science,
11 months ago
Computer Science,
11 months ago
Physics,
1 year ago
Math,
1 year ago