Wednesday, November 3, 2010

Another bit of feedback

regarding one of the practice midterms:

The question:
On the tracing ex. Y’s final value is 4. It therefore should be that the statement should be the else clause because  <>4 or <>5 is false.
Is that correct bec. On the exam’s answer you wrote that the answer is it is there, which is the then statement.

My Answer:
https://docs.google.com/document/pub?id=1ukHo2jysIGz1wXkkpsk80-d9n9vQIpzNb4lMqEUscJA&pli=1

this is a very tricky question which, if i recall correctly, nobody got right.

Indeed, Y's final value is 4.
Consider: If y <> 4 Or y <> 5 Then

y <> 4 evaluates to False
y <> 5 evaluates to True, because 4 is not 5
So, False Or True is True
This becomes If True Then

So it will go into the If clause rather than the Else clause.

As I noted, this is a very tricky question, but if you copy the code into Visual Basic, you will see that this is what happens. People get it wrong because of the disconnect between human speech, such as English, and programming languages. You read it as "if it not 4 or five" but that is not what it means.

No comments:

Post a Comment