0
Hey guys tell me that how we can get the no. Of times the loop executed means how many times loop executed
I want to apply this kind command in my coding i hope you guys get what i mean
1 Réponse
+ 12
First you need to declare a variable and increment it inside the loop to count the number of executions. The value of the variable which we get is the number of times the loop body got executed.
Example :
int cnt=0,i; // declare variable cnt for counting purpose and i for iterations
for(i=0;i<10;i++)
{
//some block of code
cnt+=1; // increment cnt by 1 every time the loop body is executed
}
System.out.println(cnt); // print the cnt value i.e. number of times the loop body is executed