"variable" is declared more than once (M107) or "variable" is used before declaration (M105)
-
Sorry if the title is a bit generic, but I am having trouble iterating arrays correctly :/
What is the recommend way if I want to iterate multiple array, using the same variable / identifier?
Showing some example code:
for (var item of collection) { // do stuff with item } for (var item of another_collection) { // Qt creator shows that "item" is declared more than once (M107) // do stuff with item }
I am not sure about how exactly hoisting works in javascript, but if I try using let instead of var, Qt Creator shows another warning:
for (let item of collection) { // do stuff with item // var "item" is used before its declaration (M105) } for (let item of another_collection) { // do stuff with item }
Although I didn't run into problems right now, I was wondering, what is the correct way to iterate through multiple lists, using the same identifier?
Do I really need to use different variables (e.g. item1, item2...) or did I miss something essential here?best regards
SyntaX -
The correct way is as you did with
let
, the warning printed by Qt Creator is a false positive.This has been reported in : https://bugreports.qt.io/browse/QTCREATORBUG-22907