Lesson goal: Comparing strings

Previous: The length of a string | Home | Next: Comparing strings (2)

When working with strings, you might want to ask true/false questions about them, and use results of these questions in a if statement. These questions often will involving checking if two strings are equal to one another, or if one may come before another (alphabetically). To do this, you can use the same operators as for numbers, which are:
• == to test for equality
• ~= to test for being not-equal
• < to test if if a string comes before another alphabetically
• > to test if if a string comes after another alphabetically

Now you try. Run this code and type in word when asked. Try words that come before and after computer alphabetically. Also try typing in computer exactly.

Type your code here:

See your results here: