Is there any difference between this code:
for(term <- term_array) {
val list = hashmap.get(term)
...
}
and:
for(term <- term_array; val list = hashmap.get(term)) {
...
}
Inside the loop I’m changing the hashmap with something like this
hashmap.put(term, string :: list)
While checking for the head of list it seems to be outdated somehow when using the second code snippet.
Instantiating variables inside for loops makes sense if you want to use that variable the
forstatement, like:And the reason why your list is outdated, is that this translates to a
foreachcall, such as:So when you reach …, your hashmap has already been changed. The other example translates to: