Answer the question
In order to leave comments, you need to log in
How to count the number of iterations in a loop?
I'm wondering how many iterations will be executed in the outer and inner loop.
for(int i=0; i < N-1; i++) {
for(int j=0; j < Ni-1; j++) {
}
}
Answer the question
In order to leave comments, you need to log in
Define an integer variable before the outer loop, make it ++ in the inner one:
int iteration_count = 0;
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < N - i - 1; j++) {
iteration_count++;
}
}
System.out.println(iteration_count);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question