Module: Conditional operator


Problem

2/17

Conditional operator - IF

Theory Click to read/hide

In the problem of finding the maximum number of two, we met a new operator that began with the word IF
This operator is called - CONDITIONAL 
The word if is translated from English as "if", and the word else - as "otherwise". If the condition after the word if is true (true), then all commands (operators) following the condition after the word  then between the words begin and end are executed >. If the condition is false (false), then the commands between begin and end after the word else are executed.

GENERAL VIEW OF THE CONDITIONAL OPERATOR:

if condition then begin // header with condition
  ... // "if" block — statements that are executed
      // if the condition in the header is true
end
else begin
   ... // "else" block — statements that are executed
       // if condition in brackets is false
end;
REMEMBER:
1. IF - ELSE  -  THIS IS ONE OPERATOR!
   Therefore, no other statements
2. after the word else NEVER CONDITION.
     Block "otherwise" is executed when the main condition specified after the word IF  - is false, i.e. not executed
3. In case, in the "if" block or in the "otherwise" block there is only one statement, then begin and end can be omitted
4. A CONDITION is an expression relative to which you can say it is true (that is, it is fulfilled) or false (that is, it is not fulfilled)
   You can use logical relationship signs in a condition
   > , <               more less
  >=, <=             greater than or equal to, less than or equal to
  =                     equals
  <>                   not equal

 

Problem

Complement the program that displays the sign "-" (minus) if the number entered from the keyboard is negative, and the "+" sign (plus) - if the number is positive (do not take into account that zero can be entered from the keyboard)

1. In line 4, instead of a comment, write the condition that you will check
2. In line 5, write the output statement that will be executed if the condition is TRUE (is true)
3. In line 8, write the output statement that will be executed if the condition is FALSE  (not satisfied)