Different ways of finding loop invariant

396 views Asked by At

I am trying to find the loop invariant of this code. Usually I would actually go through the code with an input and try to figure it out. But this approach doesn't always work. Just wondering is there a better way to find the loop invariant? Any advice will be much appreciated!

 char[] Reverse(char S[], int len){

    char tempChar;
    int count = 0;

    while(count < n/2){
        tempChar = S[count];
        S[count] = S[n-count-1]
        S[n-count-1] = tempChar;
        count = count + 1;  
    }

    return S
}
0

There are 0 answers