[CSI] Question on the Practice Quiz

Mikhail Nesterenko mikhail at cs.kent.edu
Wed Feb 2 13:50:02 EST 2022


> 
> I was having difficulty with understanding the logic on question 10 on the
> practice quiz.
>  int i=0;
>  for(int j=0; j < 3; ++j)
>     for(int k=0; k < 3; ++k)
>     	  ++i;
> 
> I ended up with 2 instead of 9 as my answer, and was wondering if you might
> be able to help explain how to get to 9.


There are three iterations of the outer-for loop. Each iteration of
the outer-for is the execution of the inner-for. Each execution of the
inner-for are three iterations of its body. The body increments "i":

3 * 3 = 9

Thanks,
--
Mikhail


More information about the cs13001 mailing list