What is a loop invariant?

后端 未结 15 1347
后悔当初
后悔当初 2020-11-28 17:13

I\'m reading \"Introduction to Algorithm\" by CLRS. In chapter 2, the authors mention \"loop invariants\". What is a loop invariant?

15条回答
  •  春和景丽
    2020-11-28 17:57

    In simple words, it is a LOOP condition that is true in every loop iteration:

    for(int i=0; i<10; i++)
    { }
    

    In this we can say state of i is i<10 and i>=0

提交回复
热议问题