Skip to main content

Posts

Showing posts from February, 2006

3 digit for loop

Would you believe that this is almost exactly the same as some JavaScript code that I found, that somebody actually wrote? Tell me, what's wrong with this code? Could you think of any more concise way to write it? All we need is the highest version number we can use to create the activex object without throwing an exception.var curr = -1; for (var n1 = 1; n1 >= 1 && curr == -1; --n1) {for (var n2 = 9; n2 >= 0 && curr == -1; --n2) {for (var n3 = 9; n3 >= 0 && curr == -1; --n3) {for (var n4 = 9; n4 >= 0 && curr == -1; --n4) {for (var n5 = 9; n5 >= 0 && curr == -1; --n5) { var version = "" + n1 + n2 + n3 + "_" + n4 + n5; try{ var versioned = new ActiveXObject("JavaPlugin." + version); curr = new Number("" + n1 + n2 + n3); }catch (e) {continue; } } } } …