The loop invariant

1
2
3
4
5
p=1
i=0
while p<n:
    p=2*p
    i+=1

Consider the above fragment of code, with \(n\), \(p\) and \(i\) as integer variables. What is the loop invariant of the code?

Definition: A loop invariant is a condition that is necessarily true immediately before and immediately after each iteration of a loop

×

Problem Loading...

Note Loading...

Set Loading...