What are Case Statement Data Types?

What are Case Statement Data Types? thumbnail
Case statements are used in programming.

If-then statements are critical to any programming language. They allow programs to perform different actions in different circumstances. The most basic example of an if-then statement is when you log in to your email account. "If" your password is correct, "then" you can see your mail. "If" you give the wrong password, "then" you are told your password was incorrect. Case statements are derivations of if-then statements.

  1. Switch Case Statements

    • Case statements are the functional components of what are called "switch case" statements in the C programming language, or simply "switch" statements in Java. These are like if-then statements, but somewhat streamlined. Instead of a number of separate "if-then" statements, switch-like statements take a single variable, then have a list of case statements. Each one specifies a possible value of the variable passed into the switch-like function, and if the variable matches a case statement's conditional, or a value to which the variable passed into the switch like function is being compared, then the corresponding code is executed by the computer.

    Switch Case Statements vs. If-Then Statements

    • In basic function, switch case statements work like if-then statements: each gives a series of possibilities of code that could be executed. Switch case statements have the benefit of giving the programmer a cleaner syntax to examine than traditional if-then statements. Case statements consist solely of "case" followed by the conditional, then the code to execute beneath it. This allows the programmer to quickly ascertain all the relevant information about the block of code when he is debugging a program.

    Data Types

    • Case statements can handle most data types. These include byte, which can hold binary data, char, which holds a single character, and int, which holds an integer. They cannot handle more advanced data types, such as float or decimal, which hold numbers with decimal components. They they can handle enumerated data types, though. These are data types in which the user declares a name for a custom variable, then defines the possible values the variable can hold.

    Data Type Consistency

    • Regardless of the data type the programmer is using in the case statement, it has to be consistent between the variable that the computer will compare to case statements and the case statement conditionals. A computer can only compare int variables to int variables, char variables to char variables, enumerated variables to another instance of that same enumerated variable and so on. If there is a discrepancy between the two data types, then the program will fail to compile.

Related Searches:

References

  • Photo Credit Ablestock.com/AbleStock.com/Getty Images

Comments

You May Also Like

  • How to Use a CASE Statement in SQL

    The Structured Query Language (SQL) is a programming platform for databases. It is possible to create a database from scratch, enter data,...

  • How to Write a Case Statement in C++

    As computer programs are not limited to the linear or sequential execution of commands, programming language constructs support run time branching of...

  • What Is the Computer Program Excel?

    Microsoft Excel is a spreadsheet program designed to help maintain databases. Additionally, it can complete mathematical functions and analyze data. Learning how...

  • How to Use Case Tutorials

    The Switch-Case statement common to most programming languages provides an easier and more readable way to handle decisions when there are a...

  • Homemade PC Case

    If you are looking for a computer that is yours and yours alone, one of the best ways to achieve your goal...

  • How to Use a Switch Case with Ranges in C++

    Switch cases exist to make writing if/else statements easier. Every "switch" statement in C++ can be re-written as a large connection of...

  • How to Use the Most Common Numeric MySQL Data Types

    Each column in a MySQL database has a type--or a specific kind of data that it will store. Good database programming takes...

  • How to Use a Switch Statement in C

    The switch statement is a powerful programming structure that exists in most programming languages. It will allow you to write a section...

  • How to Execute a SQL Command From a Case Statement

    Type the following code into the text editor, which gives you an example of how to use the case statement: SELECT title,...

  • How to Use a Switch Statement

    The switch statement is used in programming languages such as C, C++, Javascript and Java. When you desire to code a logical...

  • How to Use an If Then Statement in Excel

    The IF function, or statement, says to a computer program "if this happens, then do this." Many programming languages use IF statements...

  • How to Use Logic Statements in Excel

    Any worksheets you have saved in the Microsoft Excel software can be modified by using the Visual Basic for Applications (VBA) programming...

  • How to Use a Switch Case

    The switch-case statement in an important tool for cleanly controlling the flow of a program. It functions identically to a long list...

  • ANSI C Data Types

    ANSI C Data Types. The American National Standards Institute (ANSI) standard for the C computer programming language remains true to the minimalist...

  • How to Access VBA Data Types

    Knowing how to determine the data type of a particular field in a table can make your database application more dynamic. Microsoft...

  • Types of Financial Statement Fraud

    Types of Financial Statement Fraud. When the managers of a company provide false financial information, it's called financial statement fraud. Financial statement...

  • What Is a Program Statement?

    A computer program statement is an instruction for the computer program to perform an action. There are many different types of statements...

  • What Business Decisions Could Be Made Using the Income Statement?

    An income statement provides a trove of operating data that a business owner can use to improve corporate operations. If you're an...

Related Ads

Featured