def afunction
a = "xyzzy"
puts a
change_local_a
puts a
end
afunction
if (divElements[j].className == "quotebox") {
var strongElement = divElements[j].childNodes[0];
var whoSaid = strongElement.innerHTML.split(" ", 1)[0].toLowerCase();
for (var k = 0; k < usersToIgnore.length; k++) {
if (usersToIgnore[k] == whoSaid) {
divElements[j].childNodes[1].innerHTML = "IGNORED";
break;
}
}
}
if (divElements[j].className == "quotebox") {
var strongElement = divElements[j].childNodes[0];
for (var k = 0; k < usersToIgnore.length; k++) {
if (strongElement.innerHTML.match(new RegExp(usersToIgnore[k],"i"))) {
divElements[j].childNodes[1].innerHTML = "IGNORED";
break;
}
}
}
int i;
i = f(); // Bad – initialization separate from declaration
int j = g(); // Good – declaration has initialization
Note that gcc implements for (int i = 0; i < 10; ++i) correctly (the scope of i is only the scope of the for loop), so you can then reuse i in another for loop in the same scope. It also correctly scopes declarations in if and while statements, e.g.
while (const char* p = strchr(str, '/')) str = p + 1;
// Inefficient implementation:
for (int i = 0; i < 1000000; ++i) {
Foo f; // My ctor and dtor get called 1000000 times each.
f.DoSomething(i);
}
It may be more efficient to declare such a variable used in a loop outside that loop:
Foo f; // My ctor and dtor get called once each.
for (int i = 0; i < 1000000; ++i) {
f.DoSomething(i);
}