yes
If you must evaluate two or more expressions separately, use multiple if statements. If you only need to test all the possible evaluations of a single expression, use a switch.
A Switch statement can be considered as a series of if. else if. else statements. whatever condition is satisfied, the code block would get executed. if (cond 1) { } else if (cond 2) { } else if (cond 3) { } ...... } else if (cond N) { } else { } switch { case 1: .... case 2: .... .... case N: ... default: ... } Difference: In the if else blocks, if one condition is satisfied, all other blocks are ignored In Switch blocks, unless you have break statements inside each condition block, the subsequent blocks would not be ignored.
It's not always possible. If the expression in each if statement can be reduced to a single expression with multiple evaluations, then you can use a switch case to cater for each evaluation. If you must use separate expressions to obtain the evaluations, then you must use if, else if, else.
None of them; you may think of the conditional statements, like if-else, for, while, do-while.
Decision making statements make use of conditional expressions. In C++ there are three possibilities: if/else, switch/case and the ternary operator (?:).
if (condition) statement1 [else statement2] example: if (i==j); else if (j==k) printf ("i!=j, j==k\n); else printf ("i!=j, j!=k\n); here statement1 is an empty-statement, statement2 is another if-statement There are three forms of statements IF-THEN IF-THEN-ELSE IF-THEN-ELSIF Sequence of statements is executed only if the condition evaluates to TRUE If condition evaluates to FALSE or NULL, it does nothing In either case control passes to next statement after the IF-THEN structure IF THEN statements; END IF; Sequence of statements in the ELSE clause is executed only if the condition evaluates to FALSE or NULL IF THEN statements; ELSE statements; END IF;
In order to achieve multiple decisions in a program, you have to join multiple IF statements and use the AND logic to determine if they are true of false, whereas in a nested decision, only one statement must be true in order for it to move forward or End. If (applicant >= 21) AND (applicant <= 19) then add 1 to hireList Else add 0 to hireList End if IF condition1 THEN IF condition2 THEN ASP Statement(s) for when condition2 is met ELSE ASP Statement(s) when this condition2 is NOT met END IF END IF
Statements that use the words "always" and "never" are called absolute statements.
multiple alternative decision structure / case structure
No. An iterator can be used to iterate through only one collection. to iterate through multiple collections you must use multiple iterators.
The comma operator will let you use multiple statements in an expression in C or C++.Strictly speaking, you cannot have a statement inside an expression, for example the following is completely wrong:int n;n = 1 + for (i=0; i
You use a nested if when the condition is dependent upon another condition. For example: if (ptr != nullptr) { // ptr is non-null -- test the value it refers to if (ptr* == 0) { // the value pointed to by ptr is zero } else { // the value pointed to by ptr is non-zero } } In this case, the alternative to a nested if creates an inefficiency: if (ptr != nullptr && *ptr == 0 ) { // ptr is valid and refers to the value zero } else if (ptr != nullptr) { // ptr is valid and refers to a non-zero value } In this example, the expression "ptr != nullptr" is evaluated twice when ptr is valid and refers to a non-zero value. The nested if only evaluates this expression one time.