` case label1: statements1; break; case label2: statements2; break; case labeln; statements - N; break; default: statements; } . . . Break and Default Statement The switch statement begins by evaluating an expression placed between parenthesis, much like the if statement.
The result compared to labels associated with case structure that follow the switch statement. If the result is equal to a label, the statements in the corresponding case structure are executed. The default structure is can be at the end of a switch structure if the result of the expression that do not match any of the case labels. The break statement is also used commonly within switch to exit the statement once the appropriate choice is found.
<Html> <Head> <Title>Program - To test witch command in JavaScript </Title> </Head> <Body> <script language="javascript" type="text/javascript"> var grade= ; var marks=prompt(“Please enter your marks/ :”,” ”); if(marks> ) {grade= ;} else if(marks> )&&(marks<= ) {grade= ;} else if(marks> )&&(marks<= ) {grade= ;} Illustration . Using Switch Statement Chapter Pages else if(marks>40v)&&(marks<= ) {grade= ;} else {grade= ;} switch(grade) { case : document.write("Your Grade is Outstanding.."); break; case : document.write("Your Grade is Excellent.."); break; case : document.write("Your Grade is Good.."); break; case : document.write("Your Grade is Satisfectory.."); break; default: document.write("Your Grade Poor and have to re-appear Exam.."); } </script> </Body> </Html> The output will be - X X X OK Script Prompt: Demo Program - To test else c...i.. X Program - To test witch co... C:\User\ELCOT\Desktop\SCER Search...
Cancel Please enter your Marks/ : Explorer User Prompt ^ ^ - X X Demo Program - To test else c...i.. Your Grade is Outstanding... X Program - To test witch co... C:\User\ELCOT\Desktop\SCER Search...
^ ^ Chapter Pages . Looping / repetitive In JavaScript there are times when the same portion of code needs to be executed many times with slightly different values is called Loops. JavaScript supports three kinds of looping statements. They are • for loop • while loop • do..while loop .
. for loop The for loop is a very rigid structure that loops for a pre-set number of times. In JavaScript for