How to set up smartphones and PCs. Informational portal
  • home
  • Windows 7, XP
  • Javascript while, do-while and for loops. The if selection statement in C

Javascript while, do-while and for loops. The if selection statement in C

The second step in creating full-fledged programs in the MatLab language is to study branching and loop operators. With their help, you can implement the logic of the execution of mathematical algorithms and create repetitive (iterative, recurrent) calculations.

2.1. Conditional if statement

In order to be able to implement logic in the program, conditional operators are used. Conceptually, these operators can be represented as nodal points, reaching which the program makes a choice in which of the possible directions to move on. For example, you need to determine whether some variable arg contains a positive or negative number and display the corresponding message on the screen. To do this, you can use the if statement (if), which performs similar checks.

In the simplest case, the syntax for this if statement is:

if<выражение>
<операторы>
end

If the value of the "expression" parameter matches the value "true", then the statement is executed, otherwise it is skipped by the program. It should be noted that "expression" is a conditional expression in which some condition is checked. Table 2.1 presents variants of simple logical expressions of the if statement.

Table 2.1. Simple Boolean Expressions

True if a is less than b and false otherwise.

True if a is greater than b and false otherwise.

True if a is equal to b and false otherwise.

True if a is less than or equal to b and false otherwise.

True if variable a is greater than or equal to variable b and false otherwise.

True if a is not equal to b and false otherwise.

Below is an example of the implementation of the sign () function, which returns +1 if the number is greater than zero, -1 if the number is less than zero, and 0 if the number is zero:

function my_sign
x = 5;
if x> 0
disp (1);
end
if x< 0
disp (-1);
end
if x == 0
disp (0);
end

Analysis of the given example shows that all these three conditions are mutually exclusive, i.e. when one of them is triggered, there is no need to check the others. Implementation of just such logic will increase the speed of program execution. This can be achieved by using the construction

if<выражение>
<операторы1>% are met if the condition is true
else
<операторы2>% are met if the condition is false
end

Then the above example can be written like this:

function my_sign
x = 5;
if x> 0
disp (1);
else
if x< 0
disp (-1);
else
disp (0);
end
end

This program first checks for the positiveness of the variable x, and if so, then the value 1 is displayed on the screen, and all other conditions are ignored. If the first condition turns out to be false, then the execution of the program proceeds by else (otherwise) to the second condition, where the variable x is tested for negativity, and if the condition is true, the value -1 is displayed on the screen. If both conditions are false, then the value 0 is displayed.

The above example can be written in a simpler form using one more construction of the if operator of the MatLab language:

if<выражение1>
<операторы1>% are executed if expression1 is true
elseif<выражение2>
<операторы2>% are executed if expression2 is true
...
elseif<выражениеN>
<операторыN>% are executed if expressionN is true
end

and is written as follows:

function my_sign
x = 5;
if x> 0
disp (1); % is executed if x> 0
elseif x< 0
disp (-1); % is executed if x< 0
else
disp (0); % is executed if x = 0
end

With the conditional if statement, you can test for more complex (compound) conditions. For example, you need to determine: does the variable x fall within the range of values ​​from 0 to 2? This can be implemented by simultaneously checking two conditions at once: x> = 0 and x<=2. Если эти оба условия истинны, то x попадает в диапазон от 0 до 2.

To implement compound conditions in MatLab, logical operators are used:

& - logical AND
| - logical OR
~ - logical NOT

Let's look at an example of using compound conditions. Suppose it is required to check if the variable x is in the range from 0 to 2. The program will be written as follows:

function my_if
x = 1;
if x> = 0 & x<= 2
else
disp ("x does not belong to the range from 0 to 2");
end

In the second example, we will check that the variable x does not belong to the range from 0 to 2. This is achieved by triggering one of two conditions: x< 0 или x > 2:

function my_if
x = 1;
if x< 0 | x > 2
disp ("x does not belong to the range from 0 to 2");
else
disp ("x belongs to the range 0 to 2");
end

Using the logical operators AND, OR, NOT, you can create a variety of compound conditions. For example, you can check that the variable x falls in the range from -5 to 5, but does not belong to the range from 0 to 1. Obviously, this can be implemented as follows:

function my_if
x = 1;
if (x> = -5 & x<= 5) & (x < 0 | x > 1)
disp ("x belongs to [-5, 5] but is not included in");
else
disp ("x or not included in [-5, 5] or in");
end

Note that parentheses were used in the complex compound condition. The fact is that the priority of the AND operation is higher than the priority of the OR operation, and if there were no parentheses, the condition would look like this: (x> = -5 and x<= 5 и x < 0) или x >1. It is obvious that such a check would give a different result from the expected one.

Parentheses are used in programming to change the precedence of statements. Like arithmetic operators, logical operators can also be changed at the will of the programmer. By using parentheses, the check is performed first inside them, and then outside them. That is why, in the example above, they are required to achieve the desired result.

The priority of logical operations is as follows:

NOT (~) is the highest priority;
And (&) - medium priority;
OR (|) is the lowest priority.

The ability to control the program flow allows you to selectively execute individual sections of code, and this is a very valuable programming feature. The if statement allows us to execute or not execute certain sections of code, depending on whether the condition of this statement is true or false. One of the most important uses of the if select statement is that it allows the program to take an action of its choice based on what the user has entered. A trivial example of using if is to check the password entered by the user, if the password is correct, the program allows the user to perform some action, if the password is entered incorrectly, then the program will not allow the user to access limited resources.

Without the conditional statement, the program would run the same way over and over again, no matter what input came from the user. If you use selection operators, then the result of the program can be much more interesting, since it will depend directly on the user input.

Before you begin to understand the structure of the if statement, it is worth paying attention to such values ​​as TRUE and FALSE in the context of programming and computer terminology.

True (TRUE) has a nonzero value, FALSE is equivalent to zero. When using comparison operators, the operator will return one if the comparison expression is true, or - 0 if the conditional expression is false. For example, the expression 3 == 2 will return 0 because three is not equal to two. Expression 5 == 5 evaluates to true and returns 1. If you find it difficult to understand, try printing these expressions to the screen, for example: printf ("% d", 7 == 0);

In the process of programming, it is often necessary to compare one variable with another and, based on these comparisons, control the program flow. There is a whole list of operators that allows comparisons, here it is:

Most likely you are familiar with these comparison operators, but just in case, I showed them in the table above. They should not be difficult for you to understand, most of these operators you learned in school in math lessons. Now that you understand what TRUE and FALSE are, it's time to try out the if select statement in combat. If structure:

If (conditional expression) // there is one statement here, which will be executed if the conditional expression is true

Here's a simple example of using an if statement:

If (7> 6) printf ("Seven is greater than six");

In this example, the program evaluates the conditional expression - "Is seven greater than six?" To see the result of this piece of code, just paste it into the main () function and do not forget to include the stdio.h header, run the program and see the result - true. The construction of the select operator if with curly braces:

If (TRUE) (/ * all the code that is placed inside the brackets will be executed * /)

If you do not use curly braces, then only one, the first, statement will refer to the body of the if statement. If you need to control several operators, then you need to place them in curly braces. I recommend that you always put parentheses after the if declaration - this is good programming style and you will never get confused in your code, since such a declaration is the most understandable.

Else statement

Sometimes, when the conditional expression is false, it would be convenient for some code to be executed that is different from the code that is executed when the condition is TRUE. How is this done?
Here is an example of using the if else statement:

If (TRUE) (/ * this code is executed if the condition is true * /) else (/ * this code is executed if the condition is false * /)

Else if statement

Usually, else if statements are used when multiple choice is required, that is, for example, several conditions are defined that can be true at the same time, but we only need one true conditional expression. You can use the if else statement immediately after the if selection statement, after its body. In this case, if the condition of the first selection statement is TRUE, then the else if statement will be ignored, while otherwise, if the condition of the first selection statement is FALSE, the else if statement will be checked. That is, if the condition of one if statement is true, then the others will not be checked. Now, in order to get all this well fixed in your head and understand, let's look at a simple example using select operator constructs.

#include #include int main () (int age; // no variable ... printf ("How old are you?"); // ask the user about his age scanf ("% d", & age); // user input the number of years if (age< 100) { // если введенный возраст меньше 100 printf ("Вы очень молоды!\n"); // просто показываем что программа сработала верно... } else if (age == 100) { // используем else для примера printf("Молодость уже позади\n"); // \n - символ перевода на новую строку. } else { printf("Столько не живут\n"); // если ни одно из выше-перечисленных условий не подошло, то программа покажет этот вариант ответа } return 0; }

Let's take a look at interesting conditional expressions using boolean operators.

Boolean operators allow you to create more complex conditional expressions. For example, if you want to check if your variable is greater than 0 but less than 10, then you just need to use the logical operator - AND. This is how it is done - var> 0 and var< 10 . В языке СИ есть точно такой же же оператор, только обозначается он иначе — && .
When using if statements, it is often necessary to check several different conditions, so it is very important to understand the logical operators OR, NOT, and AND. Boolean operators work in the same way as comparison operators: they return 0 if they are false or 1 if the boolean expression is true.
You can read more about logical operations in.

In this article, we will continue to explore PHP basics and talk about loops and conditions. The first step is to consider the IF - ELSE construct, which allows you to perform certain actions depending on whether a condition is met or not. Then we'll move on to looking at loops. In total, three loop constructs will be considered - these are WHILE, DO - WHILE loops and FOR loop.

PHP basics. IF - ELSE constructs

The IF - ELSE construct allows you to perform certain actions depending on whether the conditions are met or not. This construction can be widely used in practice, for example, to create a simple protection of a section of the site with a password. If the user enters the correct password, then he is given access to the private section. Otherwise, we can give him, for example, an error message.

In practice, the IF - ELSE construction looks like this:

So let's comment. The variables are assigned values ​​first. Then a condition is set. If the variable $ a is equal to the variable $ b, then the code that is in the first curly braces is executed. If the condition is not met, then everything in the first curly braces is skipped and the code that is in the curly braces after the ELSE is executed. As you can see, everything is banal, simple and understandable.

In addition to simple conditions in PHP, you can use several conditions and IF - ELSE statements. Let's take a look at the following code as an example:

"; if ($ e! = $ c) (echo" Variable E does not equal variable C
";) else (echo" Variable E is equal to variable C
";)) else (echo" Variables are not equal
"; } ?>

First, we assign specific values ​​to the variables. Then there are nested IF - ELSE constructs. As you can see in PHP, each IF - ELSE construct can contain other similar constructs, the number of which, in principle, is not limited.

Now let's look at the signs that are used in the conditions.

  • == - in PHP this sign means equals... The "=" sign in PHP is an assignment sign.
  • != not equal, for example, $ a! = $ b - the variable $ a is not equal to the variable $ b.
  • and or &&- mean AND, for example, $ a! = $ b && $ c! = $ d - the variable $ a is not equal to the variable $ b and the variable $ c is not equal to the variable $ d.
  • or or ||- mean OR, for example, $ a! = $ b || $ c! = $ d - the variable $ a is not equal to the variable $ b or the variable $ c is not equal to the variable $ d.

So, we figured out the interpretation of all the signs. Now let's get down to reading the above code, which in words can be summarized as follows:

If the variable $ a is equal to the variable $ b and the variable $ c is equal to the variable $ d or the variable $ e is equal to the variable $ d, then we display the message "Variables are equal" and make a line break. Then we do one more check. If the variable $ e is not equal to the variable $ c, then we display the message "Variable E is not equal to variable C" and do a line break. If the condition is not met, then we output "Variable E is equal to variable C". If the first condition is not met, then all the code in the first curly braces is skipped and the message "Variables are not equal" is immediately displayed and a line break is made (tag
).

This concludes our consideration of the IF - ELSE construction. I hope you understood the whole point of the above and we move on to further study. PHP basics- the study of cycles.

PHP basics. WHILE and DO - WHILE loops

Loops in PHP are very widespread, as they allow you to implement many of the functions that are present in every dynamic site. One of the most common tasks that can be solved using loops is, for example, displaying the latest website news. The whole point of loops is to perform a specific action as long as a condition is met. For example, let's solve the problem of calculating the sum of numbers from one to 10. In this case, the number of numbers can be any, but as an example, let's take the number 10, since in this case it will be easier to check the result.

To solve this problem will be used WHILE cycle... The code for calculating the sum of numbers from one to ten will be as follows:

First, we set up the variables $ s (sum) and $ i (counter) and assign values ​​to them. Then we write the WHILE loop, in the condition of which we indicate that the loop should be executed until the variable $ i (counter) is less than or equal to 10. In the body of the loop we write the value of the variable $ s and increase the counter $ i by one. This is done using two + signs ($ i ++) or by simply adding one ($ i = $ i + 1). The counter value must be changed without fail to avoid looping (infinite loop execution).

Now let's take a look at how the program is executed. First, we assign a value to the variables. Then the condition is checked in the loop. If it is executed, then the code that is in the body of the loop (in curly braces) is executed. After executing the body of the loop and increasing the value of the counter, the condition is checked again and, if it is satisfied, the loop is repeated again. The loop will repeat as long as the condition is met. After running the loop, the result is displayed using the Echo output statement. You can find more details about variables and output operators in the article "".

The DO - WHILE loop works the same way. The only difference here is that the condition check is performed after the loop has completed. Thus, the execution of the cycle will occur at least once in any case. In practice, the DO - WHILE loop looks like this:

As you can see, in solving the problem of calculating the sum of numbers from one to ten using the DO - WHILE loop, you first assign values ​​to the variables. Then the code is executed and the value of the counter is incremented, and only after that the condition is checked. If it is executed, then the cycle repeats again. Otherwise, the result is printed to the screen using an output statement.

PHP basics. FOR loop

With a FOR loop, you can do all the same things as with a WHILE loop. It is also used when creating sites, but, in my opinion, to a lesser extent than the WHILE loop. Personally, I prefer the latter, but within the framework of this article we will also look at the FOR loop, since it is part of the PHP language and you need to know it.

Let's look at how to solve the previous problem using a FOR loop. The code for calculating the sum of numbers from one to ten using a FOR loop would look like this:

As you can see, the syntax for a FOR loop is as follows. First, the variables are initialized, then the condition is indicated, after which the action to be performed after the passage of one cycle is indicated. Schematically, it will look something like this:

For (initialization; condition; action after executing one loop) (Loop body (action))

As you can see PHP syntax similar to C ++ syntax. If you have studied C ++, then it will be easier for you to learn PHP. But even if you have not studied other programming languages ​​before, you can easily master the basics of PHP, since it is one of the simplest programming languages.

This concludes this article on PHP basics. If you liked my style of writing articles and their very content, you can subscribe to the site news in any way convenient for you in the "Subscription" item.

That's all. Good luck and see you soon on the blog pages.

C ++ provides a standard set of operators for selecting a selection and cycles.

The keywords related to the construction of branching conditions for the code are:

  • switch
  • break
  • default

The key words relating to the construction of cycles are:

  • while
  • break
  • continue

Condition statements

The If statement

The condition construct using the if statement is formed as follows:

Int x = 56; bool check_x () (if (x> 0) return true; return false;)

In this case, the condition is placed in parentheses after the if statement. In this construction, the return code is true; Will be executed if x is greater than 0. next line return false; No longer applies to the code that will be executed when the condition is met. In condition constructs, if this condition is met, only one line of code will be executed if the code is not enclosed in curly brackets, that is, if the body of the code executed on condition is not formed. Let "s consider two variants of the code:

First option:

Int x = 56; bool check_x () (if (x> 0) x = 0; return true; return false;)

In this code, return true; Will always be executed, because only the string x = 0 is relevant to the code being executed;

Second option:

Int x = 56; bool check_x () (if (x> 0) (x = 0; return true;) return false;)

In this code, return true; Will be satisfied only if the condition x> 0 is satisfied.

The else statement

The else statement is used in conjunction with the if statement to form a sequence of conditions.

Int x = 56; bool check_x () (if (x> 0) (x = 0; return true;) else if (x< 0) { x = 0; return false; } else { return false; } }

The else statement can be used to add a new condition if the previous condition, else if statement, fails. And as a final code in a sequence of conditions, if the previous conditions were not met. Alternatively, it is possible to use the braces for the code body if the code fits in one line.

Statements switch, case, break, default

The switch case construct is used to select the branching of the code, in the condition of which the choice is made by integer values. This means that the switch case can be used for just integer values, enumerations, and selections by the symbol code.

Int x = 100; bool check_x () (switch (x) (case 0: return true; case 50: x = 0: break; case 100: return false; default: return false;)

In the above code, the variable x is checked to be equal to the numbers 0, 50, 100. The default operator selects the code that is executed if none of the conditions are met. Note also that in the code block with case 50: added a break statement, this statement exits the condition, while the return statement exits the function. If you do not add a break statement, the code execution will continue in case 100 :. Due to this peculiarity of switch case construction, it is possible to combine conditions for which it is necessary to execute the same code. For example:

Int x = 100; bool check_x () (switch (x) (case 0: case 50: case 100: return true; default: return false;))

Thus, for x equal to 0, 50, 100, the function returns true, while for all other values ​​the function returns false.

Also, the code for selecting case in this construct can be wrapped in blocks of code, which will limit the scope and use declarations of variables with the same name.

Int x = 100; int check_x () (switch (x) (case 0: (int y = 1; return y;) case 50: (int y = 2; return y;) case 100: (int y = 3; return y;) default : return x;))

Thus, by restricting the scope, we are able to use variables with the same names in case conditions. But do not forget that outside the scope, bounded by curly brackets, the variable y will not exist in this case.

Cycle operators

The while statement

The while statement repeats the code in its body as long as the condition is met. For example:

Int i = 0; while (i< 10) { i = i + 1; }

In this code i will be 10 after the loop.

The do statement

The do statement is used in conjunction with the while statement and allows the loop body to be executed at least once, before the loop condition is checked. For example:

Int i = 15; do (i = i - 5; std :: cout<< i << std::endl; } while (i >0 && i< 13);

In this code, the variable I does not initially match the condition and in the usual while loop the body code of the loop has not been executed, but since the do-while loop is used, the test will be performed after the loop body is executed. As a result, the output of std :: cout is:

You can ask, why is there 0 in the output? It does not fit the condition. Again, due to the fact that the check is performed after the code is executed in the body of the loop. That is, the body of the loop has been executed, and then a check is performed, the result of which the cycle completes its work.

The break statement

As in switch case, this statement can be used in loops. This is necessary in order to exit the loop, before the cycle condition is fulfilled. For example:

Int i = 15; while (i< 50) { if (i < 0) { break; } i = i - 5; }

In this artificial example, an eternal cycle would result because the variable i decreases instead of increasing, and by the condition of the loop, the output will be produced only if i is greater than 50. But thanks to the break statement and the test condition for the negative value of the variable i The execution of the program will exit this loop as soon as i becomes less than 0.

The continue statement

This operator allows you to abort the iteration of a loop and start a new iteration of the loop before executing all the code in the body of the loop. For example:

Int i = 0; while (i< 5) { if (i == 3) { i = i + 1; continue; } std::cout << i << std::endl; i = i + 1; }

When executing this code, we get the following output:

That is, the output of number 3 will be omitted.

The for statement

Loops with the for statement allow you to combine the initialization of variables, the condition and the change of these variables.

That is, the following while loop

Int i = 0; while (i< 10) {

It will be equivalent to the following for loop:

For (int i = 0; i< 10; i++) { // ToDo Something }

The advantage of this for loop will be that the variable I will be in the local scope of the for loop.

For loops can be initialized with several variables of the same type. For example:

For (int i = 0, * p = i< 9; i += 2) { std::cout << i << ":" << *p << " "; }

Also, the condition can be declaration, initialization of a variable. For example:

Char cstr = "Hello"; for (int n = 0; char c = cstr [n]; ++ n) (std :: cout<< c; }

Given the C ++ standard 11, the auto variable can be used as the variable type, which allows you to output the type of the variable from the initializer:

Std :: vector v = (3, 1, 4, 1, 5, 9); for (auto iter = v.begin (); iter! = v.end (); ++ iter) (std :: cout<< *iter << " "; }

Also an interesting point is that the initializer, condition and block of change can be the expression:

Int n = 0; for (std :: cout<< "Loop start\n"; std::cout << "Loop test\n"; std::cout << "Iteration " << ++n << "\n") { if(n >1) break; )

Beginning with the C ++ 11 standard, for loops, iteration has been added for containers that support iteration. For example, the vector container from the standard library:

Std :: vector v = (0, 1, 2, 3, 4, 5); for (const int & i: v) std :: cout<< i << " ";

In this code, the loop construction is as follows:

For (Retrieved from the container at each iteration of the object: container) (// Body of the cycle)

Also, Range-based for loops support the auto statement. For example:

Std :: vector v = (0, 1, 2, 3, 4, 5); for (auto & i: v) std :: cout<< i << " ";

The lesson discusses the conditional operator in Pascal ( if). Explains how to use multiple conditions in one construct ( AND and OR). Examples of working with the operator are considered

We remind you that this site does not claim to be a complete presentation of information on the topic. The purpose of the portal is to provide an opportunity to assimilate the material on the basis of ready-made solved examples on the topic "Pascal programming language" with practical tasks to consolidate the material. The Pascal assignments presented on the site are lined up sequentially as their complexity increases. The site site can be used by teachers and teachers as an auxiliary visual aid.

Before considering this topic, linear algorithms in Pascal were mainly used, which are typical for very simple tasks when actions (operators) are performed sequentially, one after another. More complex algorithms involve the use of a branching construct.

A block diagram of a conditional operator:

The Pascal conditional operator has the following syntax:

Abridged version:

if condition then statement;

Full version:

if condition then statement else statement;

The conditional operator in Pascal - if - serves to organize the progress of the task in such a way that the sequence of execution of the statements changes depending on any logical condition. A logical condition can take one of two values: either true (true) or false (false), respectively, it can be either true or false.

Compound operator

If under a true condition it is necessary to execute several operators, then according to the rules of the Pascal language, they must be enclosed in a block, starting with the service word begin and ending with the service word end. Such a block is usually called operator brackets, and this construction - compound operator:

Operator brackets and compound operator in Pascal:

if boolean expression then begin statement1; operator2; end else begin statement1; operator2; end;

Translation from the English operator of the terms will make it easier to understand its use:

IF THEN ELSE
IF THEN OTHERWISE


In a condition (in a logical expression), relational operators are used.
Consider a list of Pascal relation operators:

  • more>
  • less
  • greater than or equal in Pascal> =
  • less than or equal in Pascal
  • comparison in Pascal =
  • not equal in Pascal

Example: find the largest of two numbers

Option 1 Option 2


Understand the work in detail You can use the conditional operator in Pascal by watching the video tutorial:

Example: calculate the value of the variable y along one of the two branches

Show solution:

var x, y: real; begin writeln ("enter x"); read (x); if x> 0 then y: = ln (x) else y: = exp (x); writeln ("y =", y: 6: 2) (the total number will occupy 6 positions, and there will be 2 decimal places in it) end.

Notice how y is displayed in this example. When inferring type variables in pascal, you can use the so-called formatted output, or notation with two colons:
y: 6: 2
- the number after the first colon (6) indicates how many characters the number will take when displayed on the screen
- the digit after the second colon (2) indicates how many digits after the decimal point of the real number will be displayed

Thus, the use of such a notation in pascal practically allows rounding to hundredths, thousandths, etc.

Problem 0. Calculate the value of the variable y along one of the two branches:

Objective 1. Two numbers are entered into the computer. If the first is greater than the second, then calculate their sum, otherwise - the product. The computer should then print the result and the text PROBLEM SOLVED

Objective 2. The dragon grows three heads every year, but after it turns 100, only two. How many heads and eyes does a dragon have N years?

Boolean operations in Pascal (in boolean terms)

When it is necessary to use a double condition in Pascal, then boolean operations are needed.

  • Logical operation AND (And), put between two conditions, says that both of these conditions must be met at once (must be true). The logical meaning of the operation is "conjunction".
  • Between two conditions, the sign OR (OR) says that it is enough if at least one of them is satisfied (one of the two conditions is true). The logical meaning of the operation is "disjunction".
  • In Pascal XOR - a sign of a logical operation, which has the meaning of "strict disjunction" and indicates that it is necessary that one of the two conditions is fulfilled (true), and the other is not fulfilled (false).
  • Logical operation NOT before a logical expression or variable has the meaning "negation" or "inversion" and indicates that if the given variable or expression is true, then their negation is false and vice versa.

Important: Each of the simple conditions must be enclosed in parentheses.

Example: Consider examples of logical operations in logical expressions in Pascal

1 2 3 4 5 6 7 8 var n: integer; begin n: = 6; if (n> 5) and (n<10 ) then writeln ("истина" ) ; if (n>7) or (n<10 ) then writeln ("истина" ) ; if (n>7) xor (n<10 ) then writeln ("истина" ) ; if not (n>7) then writeln ("truth"); end.

var n: integer; begin n: = 6; if (n> 5) and (n<10) then writeln("истина"); if (n>7) or (n<10) then writeln("истина"); if (n>7) xor (n<10) then writeln("истина"); if not(n>7) then writeln ("truth"); end.

Example: The company recruits employees from 25 to 40 years inclusive. Enter the age of the person and determine if he is suitable for the given company (output the answer "suitable" or "not suitable").
Peculiarity: it is necessary to check whether two conditions are fulfilled simultaneously.

Example: An integer A is given. Check the truth of the statement: "The number A is odd."

Top related articles