Assignment 7, Conversions and short-circuit evaluation
Due  October 21st, 12 noon
(To be done with your group)

  1. In this question we will discusses the issues with short-circuit evaluation.
    1. Give an example that illustrates the usefulness of short circuit evaluation.  Explain your example.
    2. Discover and indicate whether or not mystery uses short-circuit evaluation of boolean operators (i.e., AND).  Use this link to submit programs.  You should provide evidence that supports your argument.  Your program should not execute PRINT more than three times.  You will lose 5% of the points for this question for each additional executed PRINT. 
  2. Even though Java's narrowing conversions for primitives may fail (e.g., cause an overflow), they never result in a run-time exception (i.e., the program continues as if nothing bad happened).  An alternative to this is to stop program execution and report a problem.  Discuss the relative merits of the two alternatives.  You may want to read the section on "narrowing primitive conversions" and "widening primitive conversions" in the Java language definition before answering this question.
  3. Read the description of the FOR statement in the Modula-3 language definition (available from the "Interesting Links" section of the class web page).  Answer the following questions about Modula-3's FOR statement :
    1. Can the loop index variable be modified inside the loop?  Give quotes from the language definition to justify your answer.
    2. What is the scope of the loop index variable?  Give an example of a Modula-3 FOR statement and point out the scope of the index variable in the example.  Give quotes from the language definition to justify your answer.
    3. What happens if the "first" or "last" or "step" are modified in the loop body? ("first", "last", and "step" are defined in the section on FOR statement in the Modula-3 definition).  Give quotes from the language definition to justify your answer.
    4. The section on FOR statements in Modula-3's language definition shows how to rewrite the FOR statement using a WHILE statement.  Consider for this part that "step" is 1.  Will the WHILE statement correctly emulate a FOR statement if "last" is maxint?
    5. Describe how Modula-3's for statement is different from C++'s for construct.
    6. Discuss whether you prefer Modula-3's FOR statement or C++'s for construct.
  4. How does the guarded command differ from an IF statement in C++?  Give and discuss an example that illustrates the difference between the two.