Fall-Through is a specific condition in switch-case conditions, where a case doesn't have a 'break' statement at the end of the case code, and the consecutive cases are prone to execution till a break statement is encountered. I'll elaborate on this by giving you an example of a normal switch case statement where every non-default case HAS a break statement:
- int a=1;
- switch(a) {
- case 1:
- a=2
- break;
- case 2:
- a=1
- break;
- default:
- a=a;
- break;
- }
As we can see here, non-default cases 1 and 2, have a break statement at the end of their code snippets. This means that if a=1, case 1 will be executed and after the execution of the snippet, a break statement will be encountered. This will remove the control from within the switch block and transfer it to the next line of code. The final value of a will be '2' after case 1 executes.
The following is an example of the same code WITHOUT the break statements:
- int a=1;
- switch(a) {
- case 1:
- a=2
- case 2:
- a=1
- default:
- a=a;
- }
As we can see, there are no break statements in this code. The control will go to case 1 upon match first, but after the execution of case 1, the control will then 'fall-through' to case 2, and then to the default case as well. Here, the final value of a will be '1'.
It seems as though you're starting out with JAVA. You can get a better understanding of the basic concepts with some hands-on instructions in this video: