Try the fastest way to create flashcards
Question

# Count the number of iterations in the following loops. a int count = 0; while (count < n) { count++; }  b for (int count = 0; count <= n; count++) { }  c int count = 5; while (count < n) { count++; }  d int count = 5; while (count < n) { count = count + 3; } 

Solution

Verified
Step 1
1 of 2

A: loop gets iterated $\textbf {n times}$

B: loop gets iterated $\textbf {n + 1 times}$ as the condition is true also when count is equal to n

C: loop gets iterated $\textbf {n - 5 times}$ as the initial count value is already 5

D: loop gets iterated $\textbf {(n - 5)/3 times}$ as the initial count value is already 5 and it is incremented by 3 in each iteration

## Recommended textbook solutions #### Introduction to Java Programming, Brief

8th EditionISBN: 9780132130790 (1 more)Y. Daniel Liang
500 solutions #### Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
948 solutions #### Introduction to Algorithms

3rd EditionISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions #### Introduction to Algorithms

4th EditionISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
945 solutions