banner 728x90

Simplified SWITCH Statement

In Mobile Web Development 60 views
banner 728x90

Just a quick one today that might help you clean up some code somewhere.

I have a process where we are importing some glossary terms for 5 different languages. All of the logic is identical except for the LanguageID. So I have a simple FOR loop that runs 5 times, the problem is that the Language ID for each loop needs to be different, and there is no logical connection between which pass of the loop and the LanguageID number. So I had code similar to this:

2014-11-13_1002

Nothing wrong with that code, but that big long SWITCH statement was distracting to me and made it harder to follow the logic at a glance. I knew there was a cleaner way to do it, so after a few searches in the online help, I found the syntax for a “Simplified SWITCH Statement”. If the comparison value is a series of consecutive integers, in my case 1 – 5, you can use a simplified version of the SWITCH statement like this:

2014-11-13_1014

Nothing earth shattering there by any means, but it does let you see the important portion of the the logic, the import code, without being distracted by 12 lines of a SWITCH statement

Now, back to your regular schedule program….

banner 728x90
author
Author: 
    Resetting of file changes with git
    Resetting of file changes with git
    There are many different philosophies when it
    DDoS protection by Incapsula (sponsored)
    DDoS protection by Incapsula (sponsored)
    DDoS security is an incredibly important protection
    Long e-mail discussions: Be Gone !!
    Long e-mail discussions: Be Gone !!
    We've all been working on those long
    Changes to permissions for AWS Mobile Hub
    Changes to permissions for AWS Mobile Hub
    Until recently, when you first created an

    Leave a reply "Simplified SWITCH Statement"

    Must read×

    Top