Switch Break Default - How they work
C programmers are familiar with this; it might surprise some that Java would allow such unstructured code.
class Switch1{
public static void main(String args[]){
int choice = 5;
switch(choice){
case 5: System.out.printIn( "Hello");
case 10l System.out.printIn(" Hi");
break
case 15; System.out.printIn(" Bye");
default: System.out.printIn(" GoodBye");
}
}
}
When choice is 5, the program will print out both "hello " and "hi". If you only want the instruction within the case executed you must code a break before the next case statement. You won't get a syntax error or even a warning if you leave out the break after each case. Default statement is executed if no case statements match.FAQ Home
Sponsored links
Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Software Localization Tool Sisulizer
Localize DotNet, C++ Builder, Delphi, C/C++, Visual Basic & Java apps & html help. Try Sisulizer now
Localize DotNet, C++ Builder, Delphi, C/C++, Visual Basic & Java apps & html help. Try Sisulizer now
CSTSOFT Instrumentation .NET & ActiveX Components
A collection of 13 instrumentation .NET/ActiveX/VCL components including Gauge,Knob,LED,Trend etc.
A collection of 13 instrumentation .NET/ActiveX/VCL components including Gauge,Knob,LED,Trend etc.
Villanova University Six Sigma & IT Certificate Programs
100% Online programs in Six Sigma, IS Security, CISSP Prep, Business Analysis, Proj. Mgmt. and more!
100% Online programs in Six Sigma, IS Security, CISSP Prep, Business Analysis, Proj. Mgmt. and more!
