Exercise on Control Structures
- Hands on Exercise
Write a program using Eclipse and Lua that will do the following This is inspired by a project in which inappropriate words had to be removed from the text of user blog postings. We will just use Tables with words for both the text and the check words. This makes it simpler. Note: in this exercise use words such as "and", or "the" or "tree" as the check words so that others can view your work. Usually it is bad form to but actual swear words into programs. The case mentioned above being the exception. 1. Create two tables that are initialize with words use numeric indices note that this can be done using tableText = {"This", "is", "my", "table"} 2. Using a while loop compare the text word table against the check word table 3. If check words appear in the text words then remove them from the text words using table.remove 4. Keep the check words found in the text words in a new table 5. Use a generic for loop to print out the check words that matched 6. Use a for loop to concatenate the text works back into a string with spaces between the text words then print out the text Note that concatenation of words is a poor way of building text since concatenation causes new strings to be built on each operation. The alternative is to use table.concat(tableIdentifier)