Menus

Tuesday 26 February 2019

Control Statements in Android



Switch Statement


HOW TO USE SWITCH STATEMENT IN ANDROID/JAVA?


Switch case statements are a substitute for long if statements that compare a variable to several integral values
  • The switch statement is a multiway branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression.
  • Switch is a control statement that allows a value to change control of execution.

SYNTAX

switch(index){
    case 0:
        //Do this and this        break;
    case 1:
        //Do this and this        break;
    case 2:
        //Do this and this:        break;
    default: //For all other cases, do this        break;
}






No comments:

Post a Comment