jeudi 28 mai 2015

Switch Statement: Is the logic different in C v/s. other languages like Java?

I am going through this tutorial on C programming. It says:

The switch-statement is actually entirely different(from other languages) and is really a "jump table". Instead of random boolean expressions, you can only put expressions that result in integers, and these integers are used to calculate jumps from the top of the switch to the part that matches that value. Here's some code that we'll break down to understand this concept of "jump tables".

But, cases of switch statement needs to be compared until a match is found(otherwise default is returned.)

How is it different from multiple if-else statements then? Or, it is just a syntactic sugar? Am I missing something important here?

Aucun commentaire:

Enregistrer un commentaire