Hi,
I am having issues with a foreach loop, and I suspect it's either a dash character or an inadequate use of double quotes! Unfortunately, I cannot rename my local to avoid the dash, as this is part of a larger system of files and conventions. And I'm a bit confused with the quotes.
Here is a simplified version of my code, with what I've tried so far. The 1st loop displays the output I want, but doesn't work when I add BBB-b. The 2nd and 3rd, don't display what I intended:
Any advice is very much appreciated,
Thank you!
I am having issues with a foreach loop, and I suspect it's either a dash character or an inadequate use of double quotes! Unfortunately, I cannot rename my local to avoid the dash, as this is part of a larger system of files and conventions. And I'm a bit confused with the quotes.
Here is a simplified version of my code, with what I've tried so far. The 1st loop displays the output I want, but doesn't work when I add BBB-b. The 2nd and 3rd, don't display what I intended:
Code:
* Parameters for the loop
local AAA_years = "2001 2002"
local BBB_years = "2001 2002"
local BBB-b_years = "2001 2002"
* This works as I intended for only AAA and BBB,
* but it breaks when I add "BBB-b"
foreach country in AAA BBB {
foreach year of local `country'_years {
noi disp "Working on `country' `year'"
}
}
* Not quite what I want
foreach country in AAA BBB BBB-b {
foreach year in ``country'_years' {
noi disp "Working on `country' `year'"
}
}
* Not quite what I want either
foreach country in AAA BBB BBB-b {
foreach year in "``country'_years'" {
noi disp "Working on `country' `year'"
}
}
Thank you!

Comment