By now, your program searches for all the words stored in the area.
In this video, you will create a loop that calls the "Find Text" function for each word in the array.
This tells your program to keep searching for the words until all instances of the words are found.
You already used a "while loop” in your code.
In this video, you will use another type of loop: a "For Each" loop.
A "For Each" loop repeats a set of instructions for each item in a set.
In this case, you will repeat the "Find Text" instructions for each word stored in the array.
In the "highlightProblem" function, add a line that will use a "for each" function on the array "words."
After the array code, type “words.for each” and an open parentheses.
Next, tell the code to run the function "Find Text," for each word in the array.
After the parentheses, type “find Text” and a closed parentheses.
This code calls the “find text” function you wrote above and uses it to find and highlight each word in the array.
Try it out by running the function "highlight Problem."
The code highlights all of the words in your array!
Return to your code, and add a comment to describe the new line.
Delete the two "find Text" function calls because the “for each” loop now handles these.
Now your code uses "For each" to loop through each item in the array.
First, the code sends the word "very” to the "Find Text" function, where it is found and highlighted in every section of the document until there are no more sections to search.
Then, it moves on to repeat the steps with “totally,” and each other word in the array.
This is very powerful!
You are making the computer perform tedious, repetitive actions instantly!
Now, it's your turn.
Use a "for each" loop to search for all the words in your array.
Test the code, and ensure that every word is highlighted.
Add a comment to the code, and delete the extra calls to the "find text" function, which have been replaced with your "for each" loop.
Remember to be careful that the upper and lower case letters of your code match what you see here.