Module: Conditional operator


Problem

12/17

Incomplete conditional statement

Theory Click to read/hide

If in the "else" block you don’t have to do anything (for example: “if there is ice cream on sale, buy ice cream”, and if not ...), then the entire block “otherwise” you can omit and use an abbreviated (incomplete) form of the conditional operator:
if condition then begin
   ... // what to do if condition is true
end;
Consider an example of solving the problem of finding the maximum of two numbers, using the incomplete form of the conditional operator
 

Problem

You can formalize the solution of the problem of finding the maximum of two numbers using the incomplete form of the conditional operator.

Using the additional variable Max, the initial value of which is set equal to the value of the variable A
Next, we check if the value of variable B is greater than the value of variable Max, then it replaces the value of variable Max with the value of variable B.

Using this scheme, it is easy to find the maximum value of three or more of their numbers.