Nama : Aditya Isnugraha
Class : LM01
NIM : 1801419606
Assignment from Tri Djoko Wahjono
CHAPTER 8
- REVIEW QUESTION
11. What is unusual about C’s multiple-selection statement?
Answer :
the C switch statement has virtually no restrictions on the placement of the case expressions, which are treated as if they were normal statement labels. This laxness can result in highly complex structure eithin the switch body.
12. On what previous language was C’s switch statement based?
Answer :
ALGOL
13. Explain how C#’s switch statement is safer than that of C.
Answer :
C# has a static semantics rule that disallows the implicit execution of
more than one segment. Every segment must end with an explicit
unconditional branch statement which transfer control out of the switch
statement, or a goto, which can transfer control to one of the
selectable segments
14. What are the design issues for all iterative control statements?
Answer :
The design issues are how the iteration is controlled and where the control mechanism should appear in the loop statement.
15. What are the design issues for counter-controlled loop statements?
Answer :
The design issues for counter-controlled loop statement are what the type and scope of the loop variable are, whether it should be legal for the loop variable or loop parameters to be changed in the loop and if so, whether the change affects loop control or not, and if the lop parameters should be evaluated only once or once for every iteration.
- PROBLEM SET
10. In Ada, the choice lists of the case statement must be exhaustive, so that there can be no unrepresented values in the control expression. In C++, unrepresented values can be caught at run time with the default selec- tor. If there is no default, an unrepresented value causes the whole statement to be skipped. What are the pros and cons of these two designs (Ada and C++)?
Answer :
Ada was designed for military grade software development. The idea is that whenever you modify code in such a way that a new case emerges (for example adding a new value for an enumeration type), you are forced to manually revisit (and therefore re-validate) all the case statements that analyze it. Having a "default" is risky: you may forget that there is a case somewhere where the new case should not have been handled by the default.
11. Explain the advantages and disadvantages of the Java for statement, compared to Ada’s for.
Answer :
Java’s variable in the argument of a switch statement can be of integeral type (byte, short, int, etc), char, and String (JDK 1.7 and newer versions), but C++ can only be int or char.
12. Describe a programming situation in which the else clause in Python’s for statement would be convenient.
Answer :
13. Describe three specific programming situations that require a posttest loop.
Answer :
14. Speculate as to the reason control can be transferred into a C loop statement.
Answer :
goto statements can be used to have one cleanup sction in routine rather than multiple return statements, or used to exit out a nested loop that is very long
Tidak ada komentar:
Posting Komentar