42.6k views
5 votes
Evaluate the following code segment. What is the value of count after execution?

int count = 1;
for(int outer = 0; outer < 4; outer++)
for(int inner = 1; inner < 3; inner++)
count++;

1
3
9
12
13

User Yevgen
by
8.1k points

1 Answer

4 votes

The outerloop loops 4 times (0,1,2 and 3), and the inner loop loops 2 times (1 and 2). So that is 8 increments of count that starts at 1. This should bring count to 9.

User Kevin Gurney
by
8.7k points