is this valid syntax?

hi all ijust written this little piece of code and it compiles withou error but i want to know if it's valid syntax?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bool literal(char &achar)
{
	switch (achar)
	{
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
		case '.':
			return true;
			break;
		default:
			return false;
	}
}
Yeah, the syntax is right.

But what exactly are you trying to do?
If you are trying to check if a single character is a digit or a period then yes, the syntax is correct.

As the top cases miss 'break's, the cases will 'fall through' each other down to the return.

The break is redundant, as the function exits at the 'return true;'
@caswal, oh cool, i didn't know that, i thought if i did't put break, it would return true then go and return false also lol.

say if i did not put return true or flase but instead put cout << 1 for the other cases and cout << 2 for default and i did not use a break after cout << 1, then it would go and execute cout << 2 also right?
1. Why are you asking if it's valid syntax if it compiled? Trust the compiler. It is your friend.
2.
say if i did not put return true or flase but instead put cout << 1 for the other cases and cout << 2 for default and i did not use a break after cout << 1, then it would go and execute cout << 2 also right?
Why don't you go try it yourself instead of asking? Experimentation is a vital skill you'll have to develop
@helios, i did, it worked but i wanted to be sure. cause maybe it might not always be true so i just wanted to know
Topic archived. No new replies allowed.