Skip to main content

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;
                    }
                }
            }
        }
    }
}
:-) :-) :-) Well, I thought it was funny.

Comments

Popular posts from this blog

How (Not) to Handle Different Exceptions

Came across this sample from a certain multi-billion-dollar company, purporting to show how to implement exception handling. I slightly changed a few cosmetic details to make it anonymous. try { // ... } catch (GeneralException e) { if (e instanceof SpecificExceptionA){ // ... } else if (e instanceof SpecificExceptionB){ // ... } } This is a true actual story--you can't make this stuff up. Yeah, I thought it was pretty hilarious; so I felt like I had to share it.

Reality Checks to Demystify Buzzwords

As an IT insider, I feel I have something valuable to offer nontechnical people in terms of correcting misinformation. Here are a few simple tests for some popular buzzwords in tech. When evaluating a product or service, if you can honestly answer Yes to the reality check question, the buzzword probably truly applies. If the answer is No, it is probably fake. agile Does it make the developers happy? blockchain Does it cut out the middleman? cloud Does it automatically scale? microservice Does it only do one thing? object oriented Is it mostly made of interfaces? RESTful When requests arrive at a certain address, are they ready to use (without parsing)? unit test Does it prevent the tested code from touching anything outside itself?

Starting a company or Developing ideas?

Are you starting a company that needs software developed? Or, are you a developer with ideas? Take the chance to let us know what you want We need your input to be successful. Help us help you by sharing what problems are important. It would really help us out, and we would greatly appreciate it. Thank you.