You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Ono-chan's defense, it's usually not considered good practice to initialize a variable multiple times in the same scope; I think the more commonplace approach would be something like:
it's usually not considered good practice to initialize a variable multiple times in the same scope.
initialize t=0 ;
`
var t = 0; // Set t to a falsy value initially
var doit = function() {
for (var i = 0; i < 10; i++) {
if (random() < 0.2) {
t = 1;
}
if (t) {
println(i + ". bingo");
}
}
};
See the demo program at https://www.khanacademy.org/computer-programming/confused/5208304615768064 . It attempts to initialize a variable declared inside the body of a loop to undefined causing the complaint "It's not necessary to initialize 't' to 'undefined'." which is certainly not the case.
The text was updated successfully, but these errors were encountered: