Concept explainers
Describe the difference between the if /else if statement and a series of if statements.
“if/else”if statement:
- “if/else” ifis a conditional statement that controls the condition branching.
- It executes the statements after evaluating the conditional expression.
- The “if” statement evaluates the test expression and when it is evaluated as true, the statement inside the body of “if” statement is executed.
- If the test expression is evaluated as false, it moves to the next if/else statement and the process continues till it reaches the finalif/else statement.
- If the test expression is evaluated as false, the statements in the “else” is executed.
Syntax:
//if conditional statement
if(condition)
{
Statement1
}
//if condition statement2
else if(condition)
{
Statement2
}
//else part
else
{
Statement3
}
Series of “if” statement:
A condition statement that controls the condition branching. The “if” statement evaluates the test expression and when it is evaluatedas true, the statement inside the body of “if” statement gets executed.
Syntax:
// if conditional statement1
if(condition)
{
Statement1
}
// if conditional statement2
if(condition)
{
Statement2
}
Explanation of Solution
Difference between if/else if statement and a series of if statement:
if/else if statement | if statement |
The condition gets tested until one conditional block is found to be true. | The conditions get validated for each of the condition cases given in a series. |
The conditions are being evaluated to true to execute the statement. On evaluating true, the statement gets execute and exits the controls. | Each series of condition needs to be evaluated for the execution of series of statement present. The control gets validated for each condition and based the valuation of condition; the control exits the condition. |
Want to see more full solutions like this?
Chapter 4 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Additional Engineering Textbook Solutions
Using MIS (10th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Starting Out With Visual Basic (7th Edition)
Problem Solving with C++ (10th Edition)
Modern Database Management
Java How To Program (Early Objects)
- 0 When you write an If-Then-Else statement, under what circumstances do the statementsthat appear between Else and End If execute?arrow_forwardComputer Fundamentals and Programming 2 Write a program that determines a student’s grade. The program will accept 3 scores and computes the average score. Determine the grade based on the following rules: - If the average score is equal or greater than 90, the grade is A. - If the average score is greater than or equal to 70 and less than 90, the grade is B. - If the average score is greater than or equal to 50 and less than 70, the grade is C. - If the average score is less than 50, the grade is F. Source Codes and Print Screen of the Outputarrow_forwardMulti-way selection is possible with nested if-else statements and switch statements. When is it inappropriate to use a switch statement?arrow_forward
- 2. Write an if statement that assigns 1 to x if y is greater than 0.arrow_forward2. Write an if statement that assigns 0.3 to commission if sales is greater than or equal to 10000. C++ programming language.arrow_forward(Physics) Coulomb’s Law states that the force, F, acting between two electrically charged spheres is given by this formula: F=kq1q2r2 q1isthechargeonthefirstsphere.q2isthechargeonthesecondsphere.risthedistancebetweenthecentersofthetwospheres.kisaproportionalityconstant. Write an assignment statement to calculate the force, F.arrow_forward
- 1. An if selection statement executes if and only if: A. the Boolean condition evaluates to false. B. the Boolean condition evaluates to true. C. the Boolean condition is short-circuited. D. none of the above. Answer: 2.A compound statement is enclosed between: A. [ ] B. { } C. ( ) D. < > Answer: 4. The controlling expression for a switch statement includes all of the following types except: A. char B. int C. byte D. double Answer:arrow_forwardProblem definition: A college wants to know how well its students did on an exam. The following program summarizes the results. The program asks a user to enter the results pass (1) or fail (2) for 10 students. It displays the number of passed and the number of failed. It displays a message "Raise error" if the number of passes is more than 8 You are asked to identify statement with syntax errors by selecting them as wrong and the correct statements as rightarrow_forwardq → r r Therefore, q. -- This is an example of a _______ statement.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr