What conclusion can you draw?

You work as the Enterprise application developer at Domain.com. The Domain.com network consists of a single Active Directory domain named Domain.com. All servers in the domain run Windows Server 2003. Your responsibilities at Domain.com include the testing and stabilization of applications. Domain.com operates in the Inland Revenue services department. You are currently performing a code review for an income tax filing application. In the code review you examine the following code:

while (true)
{
TaxForm form = taxForm.Instance;
if (form = = null)
break;
Schedule schedule = form.Schedule;
if (schedule = = null)
break;
Worksheet worksheet = schedule.Worksheet;
if (worksheet = = null)
break;
worksheet.Clear();
break;
}

The code is meant to clear a worksheet. Now you need to check whether the code has any problems with its semantics.

What conclusion can you draw?

You work as the Enterprise application developer at Domain.com. The Domain.com network consists of a single Active Directory domain named Domain.com. All servers in the domain run Windows Server 2003. Your responsibilities at Domain.com include the testing and stabilization of applications. Domain.com operates in the Inland Revenue services department. You are currently performing a code review for an income tax filing application. In the code review you examine the following code:

while (true)
{
TaxForm form = taxForm.Instance;
if (form = = null)
break;
Schedule schedule = form.Schedule;
if (schedule = = null)
break;
Worksheet worksheet = schedule.Worksheet;
if (worksheet = = null)
break;
worksheet.Clear();
break;
}

The code is meant to clear a worksheet. Now you need to check whether the code has any problems with its semantics.

What conclusion can you draw?

A.
The code has no problems.

B.
The code has problems as you need to pass the value false to the while expression.

C.
The code has problems as execution will occur in an infinite loop.

D.
The code review failed as the Clear method of the Worksheet class will never get called.

Explanation:
A while true loop will prevent the need to make use of nested if statements. Thus this code does not have any problems. You simply need to ensure that you always break out of the loop after all conditions inside the loop have been tested.
Incorrect answers:
B: This is incorrect the condition would always fail and execution would never enter the loop.
C: There will not be an infinite loop because execution will break after the last break statement.
D: This is incorrect since as long as each if statement inside the while true loop fails, execution will reach the end of the loop and the Clear method will get called.



Leave a Reply 0

Your email address will not be published. Required fields are marked *