English
English
Slovensky
Slovensky
Česky
Česky
Šarišsky
Šarišsky

Condition

IF (logical expression) THEN command;

If we are writing a program we cannot know how the commands are working - Answer of a user, non-function of printer. We must forecast all of these, and program must be reliable in this way. For this are tehere a CONDITIONS, which can furcate a program . In depending up to a condition, they make up some command, prepared for this situation.

Full Condition:

IF (condition) THEN BEGIN
    command;
    ..
END
ELSE BEGIN
    command;
    ..
END

Short form

IF (condition) THEN BEGIN
    command;
    ..
END;

If is condition done, program start compliting commands between BEGIN and END.. If condition isn't done, there will be a acomplished a commands behind of ELSE. This commands are in a BODY of BEGIN and END.

There are two important things. At 1st.: in a fulll condition behind 1st END, there aren't a ; , because before ELSE we cannot to write a ;. 2nd: We need to write BEGIN - END to the condition only if a condition body have only one command....If there are more then one command, you need to write a BEGIN - END.


Logically expressions, conditions.

Logically expressions are most used in programs, which are confronting two numbers or two and more variables.

For the confrontation we have:

IF (X=10) THEN ak je x rovné číslu 10
  (X<10)   ak je x men‘ie ako 10
  (X>10)   ak je x väč‘ie ako 10
  (X<=10)   ak je x men‘ie, alebo rovné 10
  (X>=10)   ak je x väč‘ie, alebo rovné 10
  (X<>10)   ak je x rôzne od 10

Other condition we can use a few connections - AND, OR, NOT.

Nasledovná tabužka ukazuje jednoduché príklady.

IF (X=10) AND (Y=X) THEN .. ak x=10 a zároveň y=x
IF (X<Y) OR (X=Y) THEN .. ak x<y alebo x=y
IF NOT (X=Y) THEN .. ak neplatí x=y

<<Previous | Content | Next>>