I am using XCode 4.0.2 for a iOS4 project.
I have a standard "Switch" statement
switch (i) {
case 0:
int a = 0;
break
...
}
This give me an error "Expected expression" on int a = 0;.
It is very strange that "Switch" is working fine if I precede type declaration with a simple statement like this
switch (i) {
case 0:
b = 0;
int a = 0;
break
...
}
in this case the compiler gives no error (only a "unused variable a" warning).
How can that be?
Thank you.
Try something like
switch (i) {
case 0:
{
int a = 0;
}
break
...
}
Just enclose the case statement in curly brackets:
switch (i) {
case 0: {
int a = 0;
break;
}
...
}
You need to open a new scope with { }
in order to declare new variables:
switch (i) {
case 0: {
int a = 0;
break;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With