Coding-Trick: Switch-Case as unWorkable for loop

While working, I thought I could provide few tips on coding in my blog.

So, I thought to share a "short code" in a situation where you want to initialize some values. Each value is initialized by different function. You know the functions but you don't know how many values to initialize.  Uninitialized values should be 0.

Suppose values to initialize

a = f1(); 
b = f2(); 
c = f3(); 
d = f4(); 

 A normal Switch case for the above Situation :

Switch(number_of_values_to_initialize) {

case 1:
          a = f1();
          b = 0;
          c = 0;
          d = 0;
          break;

case 2:
          a = f1();
          b = f2();
          c = 0;
          d = 0;
          break;

case 3:
          a = f1();
          b = f2();
          c = f3();
          d = 0;
          break;

case 4:
          a = f1();
          b = f2();
          c = f3();
          d = f4();
          break; }


 The Shortcut for This Code is :

YOU MAY ALSO LIKE: