Need some help with a formula:
What is the quick formula/way for evaluating no. of times a loop will be processed without actually evaluating the loop?
I was told this:
(Final - Initial)/Step
final is final value
initial is initial value
step is the increment value
for <= condition increment final by one
Example 1
using formula (11- 5)/1 = 6 times which is correctCode:int i= 5; while (i <= 10) { cout << "hi" <<endl; i++; }
but
with Example 2
would print 25 and 1.Code:int count = 1; int num = 25; while (count < 25) { num = num - 1; count++; } cout <<count << num << endl
Formula (25- 1)/1 =24 times which would make the formula found not work for all cases.
Do any of you the correct formula for this?
FYI: Asking here first- will ask fellow math instructors later...
mrc