You get a bonus - 1 coin for daily activity. Now you have 1 coin

8.8. Conditional and unconditional transitions in the C language.

Lecture





In C, the branch operator in general has the following entry:
if (expression)
operator;
The C language allows the use of the if else construct , which in general has the following entry:
if (expression)
operator 1;
else
operator 2;
C also allows the use of the else if construct . In this case, the user may incorrectly read the program.
Example:
if (expression 1)
if (expression 2)
operator 1;
else
operator 2;
C language uses a shorthand record of one of the forms of branching. This form is called a conditional expression and is written as a conditional operator ?:
In general, the conditional operator has two parts and three operands. You can record it in the following way:
(expression1)? expression2: expression3;

Example: it is required to determine the greatest of two values:
1 way:
if (a
max = b;
else
max = a;

2 way:
max = (a
To resolve a situation with a previously known number of outcomes in the C language, the choice construct is used. In general, the choice is written in the following form:
switch (expression)
{
case value1:
operator1;
case value2:
operator2;
default: operator3;
}
The choice in C allows a brief recording of those values ​​of the expression for which the same action is executed.
Example:
switch (expression)
{
case value1:
case value2:
operator1;
case value3:
operator2;
}
C can use the following unconditional jumps or interrupts: break , continue, and goto . Their use basically coincides with the use in Pascal, namely: break interrupts the execution of any kind of cycles, continue - completes the current iteration of the loop, goto - goes over the label. Unlike Pascal, break can be used in C to complete a selection. Using the goto statement in the C language is considered undesirable. Tags are not specifically announced.


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Algorithmization and programming. Structural programming. C language

Terms: Algorithmization and programming. Structural programming. C language