jeudi 26 novembre 2015

Can I use switch-case inside if condition?

I'm making a robot which can avoid obstacle itself by move randomly to another way when it met an obstacle. Can I use switch-case inside if condition as a statement. Like the code below.

if(s1) {

switch(randNumber) { case 0: spincw(); break;

case 1:
spinccw();
break;

case 2:
up();
break;

case 3:
right();
break;

case 4:
back();
break;
}

}

I compiled this but it shows "error: a function-definition is not allowed here before '{' token" Somebody help me please, thank you.

Aucun commentaire:

Enregistrer un commentaire