banner 728x90

Simplified SWITCH Statement

In Mobile Web Development 32 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: 
    Script & Style Show: Episode 1: Marc Grabanski
    Script & Style Show: Episode 1: Marc Grabanski
    During this second episode of the Script
    AWS AppSync region expansion and new functions for API keys
    AWS AppSync region expansion and new functions for API keys
    AWS AppSync, a managed GraphQL service with
    What is the best time to involve your mobile app users?
    What is the best time to involve your mobile app users?
    When talking to customers about mobile analysis,
    How to make a Twitter bot with Node.js
    How to make a Twitter bot with Node.js
    Twitter bots have been in the news

    Leave a reply "Simplified SWITCH Statement"

    Must read×

    Top