Click to See Complete Forum and Search --> : Is There Something Similar In C?


LindisfarneBabe
01-24-2001, 09:12 PM
I'm totally new to programming, so please be gentle with me. So far I've been learning Pascal for about 12 weeks and have just started on C (The language of linux at last!).

In Pascal there's a thing called the 'case statement', which is very usefull with menues. Does anyone know if there's a similar thing in C and if so what it's called please?

Thanks for any help. - Lindi

Skroob
01-24-2001, 09:14 PM
Yeah its called the switch statement.

LindisfarneBabe
01-24-2001, 09:26 PM
Thanks Skroob, I've just had a look in the book and the switch statement is exactly what I want.

Thank you - Lindi.

Sterling
01-25-2001, 11:25 AM
Although the switch statement is a good deal more powerful. You can impliment simple OR logic with something like this:

switch (someint)
{
case 1:
case 2:
case 3:
/* Do some stuff */
break;
case 4:
case 5:
case 6:
case 42:
/* Do some other stuff */
break;
}


Since case blocks "fall through" if they don't encounter a break, something like that is possible. Kind of hard to read, but possible.

------------------
-Sterling
"There is no Linuxnewbie.org cabal..."