selection Also called a decision, one of the three basic logic structures in computerprogramming. The other two logic structures are sequence and loop.
In a selection structure, a question is asked, and depending on the answer, the program takes one of two courses of action, after which the program moves on to the next event.
This structure is sometimes referred to as an if-then-else because it directs the program to perform in this way: If Condition A is True then perform Action X else perform Action Y.
All logic problems in programming can be solved by forming algorithms using only the three logic structures, and they can be combined in an infinite number of ways. The more complex the computing need, the more complex the combination of structures.
We use selection statements to control the flow of execution.
The simplest selection statement is the if statement, which has two forms:
if (expression) {
statement;
}
if (expression) {
statement; } else { statement;
}
In both forms, when the controlling expression evaluates true, control passes to the controlled statement. In the second form, when the controlling expression evaluates false, control passes to the elseclause. The else clause may be controlled by another if statement (a nested if):
if (expression) {
statement;
} else if (expression) {
statement;
} else {
// ...
}
Here, the second statement only executes when the first expression evaluates false and the second expression evaluates true. If both are false, control passes to the next else clause (if any).
The switch statement allows us greater control over the flow of execution. Rather than evaluating true or false, the control expression must evaluate to a value of integral type or enumeration:
switch (expression) {
case 0: statement;
case 1: statement;
case 2: statement;
default: statement;
}
Here, the evaluation of the expression determines which case label we jump to. Execution then continues from that point until a break, return or goto statement is encountered. The default case is optional, but can be used to cater for all evaluations not handled by an explicit case. Moreover, the default case need not be the final case label.
The switch statement is most useful when selecting between enumerations:
enum traffic_light {red, amber, green};
const char* traffic_light_string (traffic_light colour) {
switch (colour) {
case red: return "Red";
case amber: return "Amber";
case green: return "Green";
}
}
We don't use a default case here because the cases alone cover all possibilities. This also gives the compiler an opportunity to check all cases really are covered; if we "forget" an enumeration (particularly with a larger enumeration), the compiler can warn us of the fact. If we include a default, we lose that ability.
The final selection statement is the conditional (ternary) operator. It is ternary because it has three operands. We use this operator to choose between two expressions (rather than two statements):
char* f (int x) {
return x==0 ? "x is zero" : "x is non-zero";
}
In this example, the function evaluates the control expression (x==0). If true, the first expression is evaluated, otherwise the second expression is evaluated.
I don't really understand your question, but maybe it is the compiler what you mean.
A C program is a computer program written using the C programming language.
c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.
You mean you have written a program, but you don't understand it? Well, how could I explain it without seeing it?
It depends on what you mean by 'types class'. Here is the shortest C program, without any 'types class': int main (void) { return 0; }
Exactly what do you mean by 'C program in Java'
If you mean who designed C, then that would be Dennis Ritchie.
I don't really understand your question, but maybe it is the compiler what you mean.
try this---> http://c-pgms.blogspot.com/2008/08/program-to-find-meanmedianand-mode_22.html
A C program is a computer program written using the C programming language.
Not sure what you mean by this question - using the exit call will exit a C program:exit (0) ;
c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.
the features of a C program
You mean you have written a program, but you don't understand it? Well, how could I explain it without seeing it?
In the source, you mean? Use a text-editor.
London Regional Cancer Program.
Selection constructs in C++if...elseswitch/caseconditional ternary operator (?:)