user49080: I’m completely new to arduino, so be polite. I’m trying to program my esp32 to drive neopixels as seven segment display. So I take a digit and pass it to switch case and in switch case I mention which led number should be lit.
`
function showDigits(digit){

switch(digit){

 case 1:
   int a[]={1,3,4,.....};
  break;

 case 2:
    int a[]={1,3,4,6,8,...};
   break;
  .
  .
  .
default:
   int a[]={1,2,3,4,5,6,7,8,9,....};
  } 
}

Now this is throwing multiple errors including redeclare of array a in same scope. Is there any better way to code this?

user42015: If you want to declare multiple variables with the same name inside different case statements, you can enclose the code inside each of them inside curly braces:
case 1:{
    Code...
break;}
case 2:
...

The curly braces will set the limits for the variables scope to just this case.

49080: <p>I’m completely new to arduino, so be polite. I’m trying to program my esp32 to drive neopixels as seven segment display. So I take a digit and pass it to switch case and in switch case I mention which led number should be lit.
`</p>

<pre><code>function showDigits(digit){

switch(digit){

 case 1:
   int a[]={1,3,4,.....};
  break;

 case 2:
    int a[]={1,3,4,6,8,...};
   break;
  .
  .
  .
default:
   int a[]={1,2,3,4,5,6,7,8,9,....};
  } 
}
</code></pre>

<p>Now this is throwing multiple errors including redeclare of array a in same scope. Is there any better way to code this?</p>
 42015: <p>If you want to declare multiple variables with the same name inside different case statements, you can enclose the code inside each of them inside curly braces:</p>

<pre><code>case 1:{
    Code...
break;}
case 2:
...
</code></pre>

<p>The curly braces will set the limits for the variables scope to just this case.</p>
