Also the loop termination condition is wrong: until i > n or not Result It should be until i >= n or not Result since s [n] is out of bounds