TL ; DR:
remove(x) takes x out of a set. A for-each loop visits every value once, in no fixed order.
HashSet<String> colors = new HashSet<>(List.of("red", "blue", "green"));
colors.remove("blue");
colors.remove("pink"); // not in it, nothing happens
for (String color : colors) {
System.out.println(color); // red and green, in any order
}
Full lesson:
s.remove(x) removes x from the set s. It returns true if x was there. If it wasn't, nothing happens and it returns false.
On a set, remove always takes the value. A set has no indexes. Careful with a List<Integer>, though. There, remove(2) removes the item at index 2.
for (String x : s) visits each value of the set once. The order isn't fixed. It may differ from the order you added the values in.
So loop over a set when the order doesn't matter. A total, a count and a check are fine.
Don't remove values from a set while you loop over it. Java stops with a ConcurrentModificationException. Remove first, then loop.
Your task
In a word game, the set found holds the words a player found. The words "qqq" and "zzz" aren't allowed. Remove both from found.
The player never found "zzz", so removing it changes nothing.
Then add up the points. A word scores one point per letter. Loop over found and add each word's length to score.
The code already prints how many words are left, and the points.
Expected output:
4 words
14 pointsFree plan: 30 tutor messages. PRO is unlimited.
