If text=hello
text=goodbye
Else if text=goodbye
text=hello
End If
does not produce an infinite loop. Though, it will make the words switch back and forth every time the post is edited or replied to.
That elseif approach doesn't work when trying to change just parts of a string — unless it goes through the string one word at a time and can only change whole case-sensitive words — and it doesn't scale well to many keywords. More realistically, the program will replace all instances of a specific word or pattern with something else, then do the same for the next word or pattern it's supposed to filter out, and so on in a finite loop. The result of trying to swap, for example, "apple" with "orange" and vice versa with this approach is that all apples become oranges, and then all oranges (including those that were originally apples) become apples. The workaround is to change apples to a third word not likely to be used (like ##tempapple##), change oranges to apples, then change ##tempapple##s to oranges. The tricky part is making sure the algorithm applies those replacements in the correct order or it won't work as expected.