I get a little bit confused on this topic since in c-code the local scope is anything between curly braces, and you can nest one local scope inside another local scope and they are all invisible to each other if you define them at a lower level.
But, in PowerShell, where are the local scope boundaries?
POWERSHELL
function myfun {
param([boolean]$yesno)
if ($yesno) {
$result = "foo"
}
else {
$result = "bar"
}
write-host "$result" # foo or bar? where does a local scope begin end?? is
# is local scope always the start of a function? and
# and all variables can be seen no matter how many curly
# braces are in the function?
}
Versus C code:
void myfun(int yesno) {
if (yesno) {
const char* result = "foo";
}
else {
const char* result = "bar";
}
printf("%s\n", result); // ERROR! result does not exist
}