Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

Switch Case Statement

Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char). The basic format for using switch case is outlined below. The value of the variable given into switch is compared to the value following each of the cases, and when one value matches the value of the variable, the computer continues executing the program from that point.

Syntax:
switch ( ) {
case this-value:
  Code to execute if == this-value
  break;
case that-value:
  Code to execute if == that-value
  break;
...
default:
  Code to execute if does not equal the value following any of the cases
  break;
}

 

Example:

int age;
cout << "What is your age: ";
cin >> age;
switch (age)
{
   case 1: cout << "You are 1 year old";
           break;
   case 2: cout << "You are 2 years old";
           break;
   case 3: cout << "You are 3 years old";
           break;
   default: cout << "You are older than 3 years";
}

 
     
   
C++ Tutorial
 
  Introduction to C++
Introduction to C++
  Variables in C++
Variables in C++
  if statement in C++
if statement in C++
  Looping in C++
Looping in C++
  break & continue statements
break & continue statements
  Switch Case Statement
Switch Case Statement
  C++ Functions
C++ Functions
  Pointers in C++
Pointers in C++
  Arrays in C++
Arrays in C++
  Strings in C++
Strings in C++
  Structures in C++
Structures in C++
  C++ File I/O
C++ File I/O
  Typecasting in C++
Typecasting in C++
  C++ Classes
C++ Classes
  Recursion in C++
Recursion in C++
  Inheritance in C++
Inheritance in C++
  Initilization Lists in C++
Initilization Lists in C++
  Enumerated Types in C++
Enumerated Types in C++
  Templates in C++
Templates in C++
  C++ Preprocessors
C++ Preprocessors
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Marketing Rule Book Ebook Marketing Rule Book
   
Download Philip and Alex's Guide to Web Publishing  Ebook Philip and Alex's Guide to Web Publishing
   
Download Biz Opp Of The Decade Ebook Biz Opp Of The Decade
   
Download Make Money With Resale Rights Products Ebook Make Money With Resale Rights Products
   
Download Algorithmic Problem Solving Ebook Algorithmic Problem Solving
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz