I want to check if a string is abecedarian (in alphabetical order).
index = 0
while index < len(s)-1:
if s[index + 1] > s[index]:
index += 1
The way your loop is written, it will return True if any pair of characters is ordered. It only returns False if all pairs fail. The first pair
ba fails the if check, but the second pair
ab passes and the function returns True.
This isn't right, because if you think about it, you can't know that a string is abecedarian until you've examined all of the characters. You should only be returning True when you're done with the loop. Conversely, as soon as you find a pair of characters that's out of order, it is safe to return False.
That's why flipping the booleans and the
< operation works.