posted 13 years ago
The following code will output Hi six times
What is the quick formula(s) way for evaluating no. of times a loop will be processed without actually evaluating the loop? Example for above
is it 105 + 1= 6
If you actually trace through the code you will see Hi is printed six times.
I thought there was a quick way to do this?
Just like to show my classes different ways to evaluate loops
What is the quick formula(s) way for evaluating no. of times a loop will be processed without actually evaluating the loop? Example for above
is it 105 + 1= 6
If you actually trace through the code you will see Hi is printed six times.
I thought there was a quick way to do this?
Just like to show my classes different ways to evaluate loops
Author and Instructor, my book
posted 13 years ago
Hi James,
The formula will look some thing like this
(Final  Initial) / Step
Where Final is the final value.
Initial is the initial value and
Step is the increment value.
for <= condition we have to increment Final by one.
In idle condition (i.e. without any conditional break or jump etc.)the loop will execute these many times.
Regards,
Kalai Selvan T.
The formula will look some thing like this
(Final  Initial) / Step
Where Final is the final value.
Initial is the initial value and
Step is the increment value.
for <= condition we have to increment Final by one.
In idle condition (i.e. without any conditional break or jump etc.)the loop will execute these many times.
Regards,
Kalai Selvan T.
James Chegwidden
Author
Ranch Hand
Ranch Hand
Posts: 201
posted 13 years ago
Formula not quite right:
prints 25 and 1
Formula given above (25 1)/1 =24 times which is not correct.
So formula does not work for all cases.
prints 25 and 1
Formula given above (25 1)/1 =24 times which is not correct.
So formula does not work for all cases.
Author and Instructor, my book
posted 13 years ago
What is the quick formula(s) way for evaluating no. of times a loop will be processed without actually evaluating the loop?
I suggest you to read some books which contain the algorithm analysis.
From your example, I know that it is required 0(n) which n representing the times of the for loop.
Hope this help
I suggest you to read some books which contain the algorithm analysis.
From your example, I know that it is required 0(n) which n representing the times of the for loop.
Hope this help
Francis Siu
SCJP, MCDBA
bacon. tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
