Value assignment inside for-loop in Scala

Viewed 16232

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.

2 Answers
Related