What is the value of balance after the following code is executed?

int balance = 10;

while (balance >= 1) {
if (balance < 9)
break;
balance = balance - 9;
}
A. -1
B. 0
C. 1
D. 2

c Before the loop, balance is 10 . The loop-continuation-condition is true (10 >= 1). In the first iteration, balance is reduced to 1 . Since 1 >= 1 is true, the loop body is executed. Since balance < 9 is true, the break statement is executed to exit the loop. So, balance is 1 after the loop is finished. The correct answer for this question is C.

Computer Science & Information Technology

You might also like to view...

Match the following terms to their meanings:

I. Autoexec II. Caption property III. Echo On IV. Expression Categories V. Conditional expression A. Text entered in this property displays on the title bar of the form in Form view B. Selecting an object in this list box causes the values or events in the Expression Values list box to change C. When set to "No" this action hides the flickering screen as the macro actions execute D. Used to determine if the action will occur E. A trusted macro action that will execute even if the database has not been trusted or the content enabled

Computer Science & Information Technology

Paragraph formatting that creates blocks of text evenly aligned on both the right and left sides of the document is known as ____.

A. left alignment B. right alignment C. justification alignment D. center alignment

Computer Science & Information Technology