Wednesday, September 21, 2016

If Statements

if:An if statement is a programming conditional statement that, if proved true, performs a function or displays information. Below is a general example of an if statement, not specific to any particular programming language.
if else:if, else statements are used to tell the computer to do something given a certain condition, and the alternative thing it should do, should that condition be false. You can also have if statements without an accompanying else statement, but not an else statement without an if statement (after all, else is what to do if the if doesn't happen). If an if's condition isn't met and it has no else, the program simply won't execute the code in the if statement and move on. Below is a very basic example of how an if, else statement looks in code, a real life example of the concept, and finally three in-depth example using real code.
switch:In computer programming languages, a switch statement is a type of selection control mechanism used to allow the value of a variable or expression to change the control flow of program execution via a multiway branch.
Switch statements exist in most high-level imperative programming languages such as PascalAdaC/C++C# and Java, and in many other types of language, using such keywords as switchcaseselect or inspect.
Switch statements come in two main variants: a structured switch, as in Pascal, which takes exactly one branch, and an unstructured switch, as in C, which functions as a type of goto. The main reasons for using a switch include improving clarity, by reducing otherwise repetitive coding, and (if the heuristics permit) also offering the potential for faster execution through easier compiler optimization in many cases.

No comments:

Post a Comment