Conditional (computer programming)

Last updated
If-then-else flow diagram If-Then-Else-diagram.svg
If-then-else flow diagram
A nested if-then-else flow diagram IF-THEN-ELSE-END flowchart.svg
A nested if–then–else flow diagram

In computer science, conditionals (that is, conditional statements, conditional expressions and conditional constructs) are programming language constructs that perform different computations or actions or return different values depending on the value of a Boolean expression, called a condition.

Contents

Conditionals are typically implemented by selectively executing instructions. Although dynamic dispatch is not usually classified as a conditional construct, it is another way to select between alternatives at runtime.

Terminology

Conditional statements are imperative constructs executed for side-effect, while conditional expressions return values. Many programming languages (such as C) have distinct conditional statements and conditional expressions. Although in pure functional programming, conditional expressions do not have side-effects, many languages with conditional expressions (such as Lisp) support conditional side-effects.

If–then(–else)

The if–then or if–then–else construction is used in many programming languages. Although the syntax varies from language to language, the basic structure (in pseudocode form) looks like this:

If (Boolean condition) Then    (consequent) Else    (alternative) End If

For example:

If stock=0 Then    message= order new stock Else    message= there is stock End If

In the example code above, the part represented by (Boolean condition) constitutes a conditional expression, having intrinsic value (e.g., it may be substituted by either of the values True or False) but having no intrinsic meaning. In contrast, the combination of this expression, the If and Then surrounding it, and the consequent that follows afterward constitute a conditional statement, having intrinsic meaning (e.g., expressing a coherent logical rule) but no intrinsic value.

When an interpreter finds an If, it expects a Boolean condition – for example, x > 0, which means "the variable x contains a number that is greater than zero" – and evaluates that condition. If the condition is true, the statements following the then are executed. Otherwise, the execution continues in the following branch – either in the else block (which is usually optional), or if there is no else branch, then after the end If.

After either branch has been executed, control returns to the point after the end If.

History and development

In early programming languages, especially some dialects of BASIC in the 1980s home computers, an if–then statement could only contain GOTO statements (equivalent to a branch instruction). This led to a hard-to-read style of programming known as spaghetti programming, with programs in this style called spaghetti code. As a result, structured programming, which allows (virtually) arbitrary statements to be put in statement blocks inside an if statement, gained in popularity, until it became the norm even in most BASIC programming circles. Such mechanisms and principles were based on the older but more advanced ALGOL family of languages, and ALGOL-like languages such as Pascal and Modula-2 influenced modern BASIC variants for many years. While it is possible while using only GOTO statements in if–then statements to write programs that are not spaghetti code and are just as well structured and readable as programs written in a structured programming language, structured programming makes this easier and enforces it. Structured if–then–else statements like the example above are one of the key elements of structured programming, and they are present in most popular high-level programming languages such as C, Java, JavaScript and Visual Basic .

The "dangling else" problem

The else keyword is made to target a specific if–then statement preceding it, but for nested if–then statements, classic programming languages such as ALGOL 60 struggled to define which specific statement to target. Without clear boundaries for which statement is which, an else keyword could target any preceding if–then statement in the nest, as parsed.

if a thenif b then s else s2

can be parsed as

if a then (if b then s) else s2

or

if a then (if b then s else s2)

depending on whether the else is associated with the first if or second if. This is known as the dangling else problem, and is resolved in various ways, depending on the language (commonly via the end if statement or {...} brackets).

Else if

By using else if, it is possible to combine several conditions. Only the statements following the first condition that is found to be true will be executed. All other statements will be skipped.

if condition then-- statementselseif condition then-- more statementselseif condition then-- more statements; ... else-- other statements;end if;

For example, for a shop offering as much as a 30% discount for an item:

if discount < 11% then    print (you have to pay $30) elseif discount<21% then    print (you have to pay $20) elseif discount<31% then    print (you have to pay $10) end if;

In the example above, if the discount is 10%, then the first if statement will be evaluated as true and "you have to pay $30" will be printed out. All other statements below that first if statement will be skipped.

The elseif statement, in the Ada language for example, is simply syntactic sugar for else followed by if. In Ada, the difference is that only one end if is needed, if one uses elseif instead of else followed by if. PHP uses the elseif keyword [1] both for its curly brackets or colon syntaxes. Perl provides the keyword elsif to avoid the large number of braces that would be required by multiple if and else statements. Python uses the special keyword elif because structure is denoted by indentation rather than braces, so a repeated use of else and if would require increased indentation after every condition. Some implementations of BASIC, such as Visual Basic, [2] use ElseIf too. Similarly, the earlier UNIX shells (later gathered up to the POSIX shell syntax [3] ) use elif too, but giving the choice of delimiting with spaces, line breaks, or both.

However, in many languages more directly descended from Algol, such as Simula, Pascal, BCPL and C, this special syntax for the else if construct is not present, nor is it present in the many syntactical derivatives of C, such as Java, ECMAScript, and so on. This works because in these languages, any single statement (in this case if cond...) can follow a conditional without being enclosed in a block.

This design choice has a slight "cost". Each else if branch effectively adds an extra nesting level. This complicates the job for the compiler (or the people who write the compiler), because the compiler must analyse and implement arbitrarily long else if chains recursively.

If all terms in the sequence of conditionals are testing the value of a single expression (e.g., if x=0 ... else if x=1 ... else if x=2...), an alternative is the switch statement, also called case-statement or select-statement. Conversely, in languages that do not have a switch statement, these can be produced by a sequence of else if statements.

If–then–else expressions

Many languages support conditional expressions, which are similar to if statements, but return a value as a result. Thus, they are true expressions (which evaluate to a value), not statements (which may not be permitted in the context of a value). The concept of conditional expressions was first developed by John McCarthy during his research into symbolic processing and LISP in the late 1950s.

Algol family

ALGOL 60 and some other members of the ALGOL family allow if–then–else as an expression. The idea of including conditional expressions was suggested by John McCarthy, though the ALGOL committee decided to use English words rather than McCarthy's mathematical syntax:

  myvariable := if x > 20 then 1 else 2 

Lisp dialects

Conditional expressions have always been a fundamental part of Lisp  . In pure LISP, the COND function is used. In dialects such as Scheme, Racket and Common Lisp  :

;; Scheme(definemyvariable(if(>x12)12)); Assigns 'myvariable' to 1 or 2, depending on the value of 'x'
;; Common Lisp(let((x10))(setqmyvariable(if(>x12)24))); Assigns 'myvariable' to 2

Haskell

In Haskell 98, there is only an if expression, no if statement, and the else part is compulsory, as every expression must have some value. [4] Logic that would be expressed with conditionals in other languages is usually expressed with pattern matching in recursive functions.

Because Haskell is lazy, it is possible to write control structures, such as if, as ordinary expressions; the lazy evaluation means that an if function can evaluate only the condition and proper branch (where a strict language would evaluate all three). It can be written like this: [5]

if'::Bool->a->a->aif'Truex_=xif'False_y=y

C-like languages

C and C-like languages have a special ternary operator (?:) for conditional expressions with a function that may be described by a template like this:

condition ? evaluated-when-true : evaluated-when-false

This means that it can be inlined into expressions, unlike if-statements, in C-like languages:

my_variable=x>10?"foo":"bar";// In C-like languages

which can be compared to the Algol-family if–then–else expressions (in contrast to a statement) (and similar in Ruby and Scala, among others).

To accomplish the same using an if-statement, this would take more than one line of code (under typical layout conventions), and require mentioning "my_variable" twice:

if(x>10)my_variable="foo";elsemy_variable="bar";

Some argue that the explicit if/then statement is easier to read and that it may compile to more efficient code than the ternary operator, [6] while others argue that concise expressions are easier to read than statements spread over several lines containing repetition.

Small Basic

x=TextWindow.ReadNumber()If(x>10)ThenTextWindow.WriteLine("My variable is named 'foo'.")ElseTextWindow.WriteLine("My variable is named 'bar'.")EndIf

First, when the user runs the program, a cursor appears waiting for the reader to type a number. If that number is greater than 10, the text "My variable is named 'foo'." is displayed on the screen. If the number is smaller than 10, then the message "My variable is named 'bar'." is printed on the screen.

Visual Basic

In Visual Basic and some other languages, a function called IIf is provided, which can be used as a conditional expression. However, it does not behave like a true conditional expression, because both the true and false branches are always evaluated; it is just that the result of one of them is thrown away, while the result of the other is returned by the IIf function.

Tcl

In Tcl if is not a keyword but a function (in Tcl known as command or proc). For example

if{$x>10}{puts"Foo!"}

invokes a function named if passing 2 arguments: The first one being the condition and the second one being the true branch. Both arguments are passed as strings (in Tcl everything within curly brackets is a string).

In the above example the condition is not evaluated before calling the function. Instead, the implementation of the if function receives the condition as a string value and is responsible to evaluate this string as an expression in the callers scope. [7]

Such a behavior is possible by using uplevel and expr commands:

Uplevel makes it possible to implement new control constructs as Tcl procedures (for example, uplevel could be used to implement the while construct as a Tcl procedure). [8]

Because if is actually a function it also returns a value:

The return value from the command is the result of the body script that was executed, or an empty string if none of the expressions was non-zero and there was no bodyN. [9]

Rust

In Rust, if is always an expression. It evaluates to the value of whichever branch is executed, or to the unit type () if no branch is executed. If a branch does not provide a return value, it evaluates to () by default. To ensure the if expression's type is known at compile time, each branch must evaluate to a value of the same type. For this reason, an else branch is effectively compulsory unless the other branches evaluate to (), because an if without an else can always evaluate to () by default. [10]

// Assign my_variable some value, depending on the value of xletmy_variable=ifx>20{1}else{2};// This variant will not compile because 1 and () have different typesletmy_variable=ifx>20{1};// Values can be omitted when not neededifx>20{println!("x is greater than 20");}

Guarded conditionals

The Guarded Command Language (GCL) of Edsger Dijkstra supports conditional execution as a list of commands consisting of a Boolean-valued guard (corresponding to a condition) and its corresponding statement. In GCL, exactly one of the statements whose guards is true is evaluated, but which one is arbitrary. In this code

if G0 → S0  □ G1 → S1 ...  □ Gn → Sn fi

the Gi's are the guards and the Si's are the statements. If none of the guards is true, the program's behavior is undefined.

GCL is intended primarily for reasoning about programs, but similar notations have been implemented in Concurrent Pascal and occam.

Arithmetic if

Up to Fortran 77, the language Fortran has had an arithmetic if statement which jumps to one of three labels depending on whether its argument e is e < 0,e = 0,e > 0. This was the earliest conditional statement in Fortran. [11]

Syntax

IF(e)label1,label2,label3

Where e is any numeric expression (not necessarily an integer).

Semantics

This is equivalent to this sequence, where e is evaluated only once.

IF(e.LT.0)GOTOlabel1IF(e.EQ.0)GOTOlabel2IF(e.GT.0)GOTOlabel3

Stylistics

Arithmetic if is an unstructured control statement, and is not used in structured programming.

In practice it has been observed that most arithmetic IF statements reference the following statement with one or two of the labels.

This was the only conditional control statement in the original implementation of Fortran on the IBM 704 computer. On that computer the test-and-branch op-code had three addresses for those three states. Other computers would have "flag" registers such as positive, zero, negative, even, overflow, carry, associated with the last arithmetic operations and would use instructions such as 'Branch if accumulator negative' then 'Branch if accumulator zero' or similar. Note that the expression is evaluated once only, and in cases such as integer arithmetic where overflow may occur, the overflow or carry flags would be considered also.

Object-oriented implementation in Smalltalk

In contrast to other languages, in Smalltalk the conditional statement is not a language construct but defined in the class Boolean as an abstract method that takes two parameters, both closures. Boolean has two subclasses, True and False, which both define the method, True executing the first closure only, False executing the second closure only. [12]

var=conditionifTrue: [ 'foo' ]     ifFalse: [ 'bar' ] 

JavaScript

JavaScript uses if-else statements similar to those in C languages. A Boolean value is accepted within parentheses between the reserved if keyword and a left curly bracket.

if(Math.random()<0.5){console.log("You got Heads!");}else{console.log("You got Tails!");}

The above example takes the conditional of Math.random() < 0.5 which outputs true if a random float value between 0 and 1 is greater than 0.5. The statement uses it to randomly choose between outputting You got Heads! or You got Tails! to the console. Else and else-if statements can also be chained after the curly bracket of the statement preceding it as many times as necessary, as shown below:

varx=Math.random();if(x<1/3){console.log("One person won!");}elseif(x<2/3){console.log("Two people won!");}else{console.log("It's a three-way tie!");}

Lambda calculus

In Lambda calculus, the concept of an if-then-else conditional can be expressed using the following expressions:

true = λx. λy. x false = λx. λy. y ifThenElse = (λc. λx. λy. (c x y))
  1. true takes up to two arguments and once both are provided (see currying), it returns the first argument given.
  2. false takes up to two arguments and once both are provided(see currying), it returns the second argument given.
  3. ifThenElse takes up to three arguments and once all are provided, it passes both second and third argument to the first argument(which is a function that given two arguments, and produces a result). We expect ifThenElse to only take true or false as an argument, both of which project the given two arguments to their preferred single argument, which is then returned.

note: if ifThenElse is passed two functions as the left and right conditionals; it is necessary to also pass an empty tuple () to the result of ifThenElse in order to actually call the chosen function, otherwise ifThenElse will just return the function object without getting called.

In a system where numbers can be used without definition (like Lisp, Traditional paper math, so on), the above can be expressed as a single closure below:

((λtrue.λfalse.λifThenElse.(ifThenElsetrue23))(λx.λy.x)(λx.λy.y)(λc.λl.λr.clr))

Here, true, false, and ifThenElse are bound to their respective definitions which are passed to their scope at the end of their block.

A working JavaScript analogy(using only functions of single variable for rigor) to this is as follows:

varcomputationResult=((_true=>_false=>_ifThenElse=>_ifThenElse(_true)(2)(3))(x=>y=>x)(x=>y=>y)(c=>x=>y=>c(x)(y)));

The code above with multivariable functions looks like this:

varcomputationResult=((_true,_false,_ifThenElse)=>_ifThenElse(_true,2,3))((x,y)=>x,(x,y)=>y,(c,x,y)=>c(x,y));

Another version of the earlier example without a system where numbers are assumed is below.

The first example shows the first branch being taken, while second example shows the second branch being taken.

((λtrue.λfalse.λifThenElse.(ifThenElsetrue(λFirstBranch.FirstBranch)(λSecondBranch.SecondBranch)))(λx.λy.x)(λx.λy.y)(λc.λl.λr.clr))((λtrue.λfalse.λifThenElse.(ifThenElsefalse(λFirstBranch.FirstBranch)(λSecondBranch.SecondBranch)))(λx.λy.x)(λx.λy.y)(λc.λl.λr.clr))

Smalltalk uses a similar idea for its true and false representations, with True and False being singleton objects that respond to messages ifTrue/ifFalse differently.

Haskell used to use this exact model for its Boolean type, but at the time of writing, most Haskell programs use syntactic sugar "if a then b else c" construct which unlike ifThenElse does not compose unless either wrapped in another function or re-implemented as shown in The Haskell section of this page.

Case and switch statements

Switch statements (in some languages, case statements or multiway branches) compare a given value with specified constants and take action according to the first constant to match. There is usually a provision for a default action ('else','otherwise') to be taken if no match succeeds. Switch statements can allow compiler optimizations, such as lookup tables. In dynamic languages, the cases may not be limited to constant expressions, and might extend to pattern matching, as in the shell script example on the right, where the '*)' implements the default case as a regular expression matching any string.

Pascal: C: Shell script:
casesomeCharof'a':actionOnA;'x':actionOnX;'y','z':actionOnYandZ;elseactionOnNoMatch;end;
switch(someChar){case'a':actionOnA;break;case'x':actionOnX;break;case'y':case'z':actionOnYandZ;break;default:actionOnNoMatch;}
case$someCharina)actionOnA;;;x)actionOnX;;;[yz])actionOnYandZ;;;*)actionOnNoMatch;;esac

Pattern matching

Pattern matching may be seen as an alternative to both if–then–else, and case statements. It is available in many programming languages with functional programming features, such as Wolfram Language, ML and many others. Here is a simple example written in the OCaml language:

matchfruitwith|"apple"->cookpie|"coconut"->cookdango_mochi|"banana"->mix;;

The power of pattern matching is the ability to concisely match not only actions but also values to patterns of data. Here is an example written in Haskell which illustrates both of these features:

map_[]=[]mapf(h:t)=fh:mapft

This code defines a function map, which applies the first argument (a function) to each of the elements of the second argument (a list), and returns the resulting list. The two lines are the two definitions of the function for the two kinds of arguments possible in this case – one where the list is empty (just return an empty list) and the other case where the list is not empty.

Pattern matching is not strictly speaking always a choice construct, because it is possible in Haskell to write only one alternative, which is guaranteed to always be matched – in this situation, it is not being used as a choice construct, but simply as a way to bind names to values. However, it is frequently used as a choice construct in the languages in which it is available.

Hash-based conditionals

In programming languages that have associative arrays or comparable data structures, such as Python, Perl, PHP or Objective-C, it is idiomatic to use them to implement conditional assignment. [13]

pet=input("Enter the type of pet you want to name: ")known_pets={"Dog":"Fido","Cat":"Meowsles","Bird":"Tweety",}my_name=known_pets[pet]

In languages that have anonymous functions or that allow a programmer to assign a named function to a variable reference, conditional flow can be implemented by using a hash as a dispatch table.

Predication

An alternative to conditional branch instructions is predication. Predication is an architectural feature that enables instructions to be conditionally executed instead of modifying the control flow.

Choice system cross reference

This table refers to the most recent language specification of each language. For languages that do not have a specification, the latest officially released implementation is referred to.

Programming language Structured if switch–select–case Arithmetic if Pattern matching [A]
thenelseelse–if
Ada YesYesYesYesNoNo
APL NoYesYesYesNoNo
Bash shell YesYesYesYesNoYes
C, C++ NoYesUnneeded [B] [C] Fall-throughNoNo
C# NoYesUnneeded [B] [C] YesNoNo
COBOL UnneededYesUnneeded [C] YesNoNo
Eiffel YesYesYes Yes NoNo
F# YesYesYesUnneeded [D] NoYes
Fortran 90 YesYesYesYesYes [G] No
Go NoYesUnneeded [C] YesNoNo
Haskell YesNeededUnneeded [C] Yes, but unneeded [D] NoYes
Java NoYesUnneeded [C] Fall-through [14] NoNo
ECMAScript (JavaScript)NoYesUnneeded [C] Fall-through [15] NoNo
Mathematica NoYesYesYesNoYes
Oberon YesYesYesYesNoNo
Perl NoYesYesYesNoNo
PHP NoYesYesFall-throughNoNo
Pascal, Object Pascal (Delphi)YesYesUnneededYesNoNo
Python NoYesYesNoNoYes
QuickBASIC YesYesYesYesNoNo
Ruby YesYesYesYesNoYes [H]
Rust NoYesYesUnneededNoYes
Scala NoYesUnneeded [C] Fall-through[ citation needed ]NoYes
SQL Yes [F] YesYesYes [F] NoNo
Swift NoYesYesYesNoYes
Tcl NoYesYesYesNoYes
Visual Basic, classicYesYesYesYesNoNo
Visual Basic .NET YesYesYesYesNoNo
Windows PowerShell NoYesYesFall-throughNoNo
  1. ^ This refers to pattern matching as a distinct conditional construct in the programming language – as opposed to mere string pattern matching support, such as regular expression support.
  2. 1 2 An #ELIF directive is used in the preprocessor sub-language that is used to modify the code before compilation; and to include other files.
  3. 1 2 3 4 5 6 The often-encountered else if in the C family of languages, and in COBOL and Haskell, is not a language feature but a set of nested and independent if then else statements combined with a particular source code layout. However, this also means that a distinct else–if construct is not really needed in these languages.
  4. 1 2 In Haskell and F#, a separate constant choice construct is unneeded, because the same task can be done with pattern matching.
  5. ^ In a Ruby case construct, regular expression matching is among the conditional flow-control alternatives available. For an example, see this Stack Overflow question.
  6. 1 2 SQL has two similar constructs that fulfill both roles, both introduced in SQL-92. A "searched CASE" expression CASEWHENcond1THENexpr1WHENcond2THENexpr2[...]ELSEexprDfltEND works like if ... else if ... else, whereas a "simple CASE" expression: CASEexprWHENval1THENexpr1[...]ELSEexprDfltEND works like a switch statement. For details and examples see Case (SQL).
  7. ^ Arithmetic if was marked as obsolescent in Fortran 90. It was deleted as of the Fortran 2018 Standard.
  8. ^ Pattern matching was added in Ruby 3.0. [16] Some pattern matching constructs are still experimental.

See also

Related Research Articles

In programming language theory, lazy evaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an expression until its value is needed and which also avoids repeated evaluations.

Lambda calculus is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. Untyped lambda calculus, the topic of this article, is a universal machine, a model of computation that can be used to simulate any Turing machine. It was introduced by the mathematician Alonzo Church in the 1930s as part of his research into the foundations of mathematics. In 1936, Church found a formulation which was logically consistent, and documented it in 1940.

In computer science, control flow is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an imperative programming language from a declarative programming language.

Combinatory logic is a notation to eliminate the need for quantified variables in mathematical logic. It was introduced by Moses Schönfinkel and Haskell Curry, and has more recently been used in computer science as a theoretical model of computation and also as a basis for the design of functional programming languages. It is based on combinators, which were introduced by Schönfinkel in 1920 with the idea of providing an analogous way to build up functions—and to remove any mention of variables—particularly in predicate logic. A combinator is a higher-order function that uses only function application and earlier defined combinators to define a result from its arguments.

In computer science, pattern matching is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually has to be exact: "either it will or will not be a match." The patterns generally have the form of either sequences or tree structures. Uses of pattern matching include outputting the locations of a pattern within a token sequence, to output some component of the matched pattern, and to substitute the matching pattern with some other token sequence.

Curry is a declarative programming language, an implementation of the functional logic programming paradigm, and based on the Haskell language. It merges elements of functional and logic programming, including constraint programming integration.

In computer programming, the ternary conditional operator is a ternary operator that is part of the syntax for basic conditional expressions in several programming languages. It is commonly referred to as the conditional operator, conditional expression, ternary if, or inline if. An expression if a then b else c or a ? b : c evaluates to b if the value of a is true, and otherwise to c. One can read it aloud as "if a then b otherwise c". The form a ? b : c is the most common, but alternative syntax do exist; for example, Raku uses the syntax a ?? b !! c to avoid confusion with the infix operators ? and !, whereas in Visual Basic .NET, it instead takes the form If(a, b, c).

Short-circuit evaluation, minimal evaluation, or McCarthy evaluation is the semantics of some Boolean operators in some programming languages in which the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression: when the first argument of the AND function evaluates to false, the overall value must be false; and when the first argument of the OR function evaluates to true, the overall value must be true.

<span class="mw-page-title-main">Boolean data type</span> Data having only values "true" or "false"

In computer science, the Boolean is a data type that has one of two possible values which is intended to represent the two truth values of logic and Boolean algebra. It is named after George Boole, who first defined an algebraic system of logic in the mid 19th century. The Boolean data type is primarily associated with conditional statements, which allow different actions by changing control flow depending on whether a programmer-specified Boolean condition evaluates to true or false. It is a special case of a more general logical data type—logic does not always need to be Boolean.

In computer programming, a guard is a Boolean expression that must evaluate to true if the execution of the program is to continue in the branch in question. Regardless of which programming language is used, a guard clause, guard code, or guard statement is a check of integrity preconditions used to avoid errors during execution.

In computer science, a relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. These include numerical equality and inequalities.

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 search and map.

The computer programming languages C and Pascal have similar times of origin, influences, and purposes. Both were used to design their own compilers early in their lifetimes. The original Pascal definition appeared in 1969 and a first compiler in 1970. The first version of C appeared in 1972.

<span class="mw-page-title-main">JavaScript syntax</span> Set of rules defining correctly structured programs

The syntax of JavaScript is the set of rules that define a correctly structured JavaScript program.

S-algol is a computer programming language derivative of ALGOL 60 developed at the University of St Andrews in 1979 by Ron Morrison and Tony Davie. The language is a modification of ALGOL to contain orthogonal data types that Morrison created for his PhD thesis. Morrison would go on to become professor at the university and head of the department of computer science. The S-algol language was used for teaching at the university at an undergraduate level until 1999. It was also the language taught for several years in the 1980s at a local school in St. Andrews, Madras College. The computer science text Recursive Descent Compiling describes a recursive descent compiler for S-algol, implemented in S-algol.

The null coalescing operator is a binary operator that is part of the syntax for a basic conditional expression in several programming languages, such as : C# since version 2.0, Dart since version 1.12.0, PHP since version 7.0.0, Perl since version 5.10 as logical defined-or, PowerShell since 7.0.0, and Swift as nil-coalescing operator.

The syntax and semantics of PHP, a programming language, form a set of rules that define how a PHP program can be written and interpreted.

The structure of the Perl programming language encompasses both the syntactical rules of the language and the general ways in which programs are organized. Perl's design philosophy is expressed in the commonly cited motto "there's more than one way to do it". As a multi-paradigm, dynamically typed language, Perl allows a great degree of flexibility in program design. Perl also encourages modularization; this has been attributed to the component-based design structure of its Unix roots, and is responsible for the size of the CPAN archive, a community-maintained repository of more than 100,000 modules.

A binary decision is a choice between two alternatives, for instance between taking some specific action or not taking it.

<span class="mw-page-title-main">TI-BASIC 83</span> Calculator programming language

TI-BASIC 83,TI-BASIC Z80 or simply TI-BASIC, is the built-in programming language for the Texas Instruments programmable calculators in the TI-83 series. Calculators that implement TI-BASIC have a built in editor for writing programs. While the considerably faster Z80 assembly language is supported for the calculators, TI-BASIC's in-calculator editor and more user friendly syntax make it easier to use. TI-BASIC is interpreted.

References

  1. PHP elseif syntax
  2. Visual Basic ElseIf syntax
  3. POSIX standard shell syntax
  4. Haskell 98 Language and Libraries: The Revised Report
  5. "If-then-else Proposal on HaskellWiki"
  6. "Efficient C Tips #6 – Don't use the ternary operator « Stack Overflow". Embeddedgurus.com. 2009-02-18. Retrieved 2012-09-07.
  7. "New Control Structures". Tcler's wiki . Retrieved August 21, 2020.
  8. "uplevel manual page". www.tcl.tk . Retrieved August 21, 2020.
  9. "if manual page". www.tcl.tk . Retrieved August 21, 2020.
  10. "If and if let expressions" . Retrieved November 1, 2020.
  11. "American National Standard Programming Language FORTRAN". 1978-04-03. Archived from the original on 2007-10-11. Retrieved 2007-09-09.
  12. "VisualWorks: Conditional Processing". 2006-12-16. Archived from the original on 2007-10-22. Retrieved 2007-09-09.
  13. "Pythonic way to implement switch/case statements". Archived from the original on 2015-01-20. Retrieved 2015-01-19.
  14. Java.sun.com, Java Language Specification, 3rd Edition.
  15. Ecma-international.org Archived 2015-04-12 at the Wayback Machine ECMAScript Language Specification, 5th Edition.
  16. "Pattern Matching". Documentation for Ruby 3.0.