2

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
}
Wobblester
  • 748
  • 4
  • 8
  • 18
  • This may be what you are looking for: [Here](http://stackoverflow.com/questions/2935295/what-is-the-best-way-of-determining-a-loop-invariant) – 1478963 Jan 29 '14 at 02:46

0 Answers0