Programming of cyclic computational data processing processes. Programming cyclic computing processes. An example of using the for statement

In programming, there are often tasks that require repeated execution of the same group of program statements with different values ​​of their operands. Such processes are called cyclical or simply cycles. A group of cyclically repeated statements forms the so-called loop body, which can be represented by either a simple or compound expression. We will call the one-time execution of the loop body iteration.

The body of a loop in a program is always preceded by loop header, containing the designation loop operator and an expression defining (directly or indirectly) the number of iterations. Note that the body of the loop is the operand of the loop operator; therefore, the header and body of the loop constitute an indivisible structural unit of the program. In the following, using the term " loop operator", we will mean both the header and the body of the loop.

To organize cycles in all programming systems, there are specialized loop operators, the use of which relieves the programmer of the need to program cycles “manually”. MathCAD supports two types of such operators - cycle with predestination For (also called loop with counter) And loop with precondition While . A description of the structure of these operators is given in Table 5.

5.4.1 Operator For

This operator should be used in cases where the number of iterations is predetermined, that is, known in advance.

Loop header of this operator (the right operand) contains a variable called parameter(or counter) cycle, And list of values this parameter. The number of elements of the list also determines the number of iterations - during each iteration, the loop parameter receives the next value from the list specified in the header.

Loop parameter has the status of an internal program variable and has all its properties (described in section 5.1.4). As a rule, the loop parameter is used on the right side of the expressions included in the body of the loop, although it is not formally prohibited to use it on the left side of expressions (that is, to the left of the local definition operator "f"). It should be remembered that if a parameter was changed in the body of the loop, its changed value will only be valid until the end of the current iteration, since before the start of the next iteration the parameter will still receive the next value from the list specified in the loop header.

Formally, it is allowed not to use the loop parameter at all in the expressions of the loop body - in this case, the list of parameter values ​​does not play any role - only the length of this list is significant, which determines the number of (possibly meaningless) iterations.

Upon completion of the last iteration, the program statement following the loop statement will be executed. In this case, the variable used as a parameter of the completed loop retains the value it had in the last one actually completed iteration[*]. Note that this value does not always coincide with the last value from the list specified in the loop header, since an “early” exit from the loop is possible when the operator is triggered Break included in the body of the loop.

List of values The loop parameter is written in the loop header after the symbol " Î ", indicating membership in a set (this symbol does not need to be entered manually - it will be automatically displayed when entering the operator For ). MathCAD allows the use three forms entries in this list: direct transfer– list elements are explicitly specified separated by commas, the parameter receives values ​​from the list in the order they appear; in ranked variable style – the elements of the list form the corresponding arithmetic series; array– list elements sequentially receive the values ​​of array elements in the order of their indices (first, columns from left to right, then rows from top to bottom).

The three programs shown in Figure 21 illustrate different uses of the operator For .

Program Fact(n) calculates the factorial of a number n . The loop operator in this program is part of a compound expression, which, in turn, is the operand of a conditional operator Otherwise. Loop parameter k obtains values ​​from an integer arithmetic series.

Program Ch(V,N,p) processes the input vector V , replacing it with the value p those elements whose indices are specified by the elements of the second input vector N . In this example, a list of loop parameter values i defined by a set of vector elements N . Note that both of these programs perform input data control and block the execution of the main algorithm if the actual program arguments are specified incorrectly.

Program L(M,z) given in the example V ), is accompanied by detailed comments and does not require explanation. This program illustrates the possibility of using multiple loop statements, one of which is included among the statements body another. Usage nested loops- a typical technique used to process multidimensional arrays.

Figure 21 – Examples of cycle programming For


Figure 22 illustrates the use of operators Break And Continue in the body of the loop. Typically, these operators are themselves operands conditional statements If or Otherwise .

Operator Break ("abort") interrupts execution of the loop and transfers control to the operator following the interrupted loop operator. Note that if the operator Break interrupted nested loop, execution of the outer loop will continue.

Operator Continue ("continue") acts differently - he interrupts only the current iteration of the loop and transfers control to the header of this loop, after which the loop is executed continues from the next iteration (unless, of course, the interrupted iteration was the last one).

Operator Break allowed to use and outside body of the cycle. In this case, the execution of the entire subroutine is interrupted, and the result of the evaluation of its last actually executed expression is returned.

Figure 22 – Examples of using operators Break And Continue

Function SumN(V) sums only those elements of the vector that contain scalar data of the numeric type, and skips the remaining elements. Function Inverse(V) forms a vector whose elements are the inverse values ​​of the corresponding elements of the original vector. Moreover, if the next element contains the number "0" or is not a scalar of a numeric type, the cycle is interrupted. Note that the operator Break in the last example it does not interrupt the program, but transfers control to the operator Return , immediately following the operator For .

5.4.3 Operator While

Unlike the operator For , statement header While (in translation - " Bye") does not contain explicit indications of the number of iterations - it contains logical expression, the value of which is automatically calculated before the beginning execution of each next iteration[†]. As long as this expression is true, the loop will continue to iterate; as soon as the expression becomes false after the completion of the next iteration, the next iteration of the loop will not be executed, and the program statement following the statement will receive control While .

Obviously, if an identically false logical expression is placed in the loop header, this loop will not complete any of its iterations, and if this expression is identically true, the loop will be infinite (the latter situation is called looping programs). In order to avoid such situations, the operands of a logical expression must include one or more variables that change their values in the body of the loop so that the loop is finite (other means can be used to prevent looping - for example, forcing the operator to exit the loop Break ).

Examples of using the operator While are shown in Figure 23. Three options for solving the same problem are given: each of the programs F0 , F1 And F2 returns the index of the first element of the source vectorV exceeding the specified valuez .

First program (example A ) adds one to the counter k in the body of the loop While until the next one k the th element of the original vector will not exceed the specified value z . After this, the loop ends and the program returns the last modified value of the variable k , which is the solution to the problem. Note that, unlike the cycle For , counter k here it is necessary to process it with separate statements: initialize (that is, assign it an initial value) before the loop operator and change its value in the body of the loop.

It is easy to see that the option A ) of the program has a significant drawback: it does not prevent the program from looping in the case when the problem has no solution, that is, when the parameter z exceeds the value of the largest element of the vector V . In this example, looping in such a situation will not really happen - but this is not the merit of our program, but of the MathCAD system, which will control the output of the vector index V outside the permissible values ​​and will generate an error message.

Free from this drawback is the option b ) of a program in which the body of the loop contains an additional check for the validity of the next index value and forcibly interrupts the loop with the operator Break in the appropriate situation with the issuance of a text message.

Perhaps the most effective solution to this problem is the option V ), which does not use the operator at all While . In this program the variable k used only to maintain “purity of style” - to exclude processing of the loop parameter i outside the operator For .

Figure 23 – Examples of cycle programming While

Goal of the work:

Study the cyclic operators for, while, do - while, learn how to compose and program cyclic algorithms.

Brief theoretical information

Loop operators are used when it is necessary to repeat certain actions (operators and operations) several times, and such sections of algorithms are called loops.

The for loop operator

The basic form of the for loop statement is:

for (expression_1; expression_2; expression_3)

operator;

Where expression_1– initial value of the cycle parameter;

expression_2– checking the conditions for continuation of the cycle;

expression_3– change of cycle parameter (correction);

operator– simple or compound operator in C language.

The operation scheme of the operator is as follows: only once, first expression_1 is calculated, then expression_2 is checked, and if it is “true”, then a cyclic section of the program is executed, then the parameter is corrected, and so on until expression_2 takes the value “false”.

For example: for (k=1; k<5; k++)

printf(“\n %d”, k);

As a result of executing this operator, the numbers from 1 to 4 are printed in a column.

You can use a variable of any basic type as a loop parameter.

For example:

for(ch=’a’; ch<=’z’; ch++) // Вывод на экран букв

printf(“ %c”,ch); // Latin alphabet

It is necessary to carefully control the structure of the for loops in the program so that you do not end up with an endless loop (from which there is no exit).

For example:

for(k=10; k>6;k++)

printf(“endless loop\n”);

Exit loop ahead of schedule in the following ways:

By additional condition;

Using the following operators:

break;- exit from the loop in which break is located, control is transferred to the first executed statement after the loop;

exit(int Kod);- exit the program;

return;- exit from the function;

Using the unconditional jump operator goto<метка>;

Early completion of the current cyclic step possible using an additional condition or operator continue, which interrupts the execution of the current loop step, i.e. skips the statements of the rest of the loop and transfers control to the head statement of the loop to adjust the parameter and check the condition.

It is prohibited to transfer control from outside to inside the loop.

Any of the for loop expressions in parentheses may be missing, but the ";" symbol can't be lowered.

For example:

for(; i<3; i++)

puts(“Hello!”);

Cyclic while and do–while statements

Basic form of the cyclic operator while:

While (condition)

operator;

Where operator

The loop runs as long as the condition evaluates to true, i.e. the expression in parentheses returns a nonzero result. This is a loop with a precondition - first the condition is checked, then the statement is executed. Therefore, the while loop will not be executed even once if the initial result of calculating the condition is 0.

Basic form of operator do - while:

operator;

while(condition);

Where operator is a simple, compound or empty statement.

Operator dowhile– loop operator with postcondition, i.e. first the statement is executed, and then the condition is checked for truth. Since in a do–while loop the condition is checked at the end of the loop, the loop will be executed at least once.

In loops like while and do–while, the same methods of early exit from the loop and early completion of the current step of the loop are allowed as in the for statement, but in the latter case, unlike the for loop, control is transferred to checking the condition. To prevent an endless loop inside the while and do–while loops, you need to provide for changing the variables included in the condition.

For example:

for (i=1;i<=300;i++) // Печать целых чисел, кратных 5

if (i%5!=0) continue;

printf(“%5d”,i);

Examples of infinite loops:

operator;

2) while(number_not_0) // Always true!

operator;

operator;

while(number_not_0); // Always true!

Among the loop operators there must be an exit condition.

Nested Loops

In the case of nested loops, one loop is inside another, for example:

for(i=nn;i

for(j=mn;j

operator;

Where operator is a simple, compound or empty statement. The inner loop will be executed for each value of parameter i that satisfies the condition of the outer loop.

Example:

for(i=1;i<10;i++) // Печать таблицы умножения

for(j=1;j<4;j++)

printf(“\n %d*%d=%2d”, i, j, i*j);

printf(“\n”);

An example of using the for statement

Calculate. The program should print intermediate and final results.

The program text may look like

#include

#include

puts(“Enter N”);

scanf(“%d”,&N);

for (s=0, k=1; k<=N; k++) // В заголовке цикла можно выпол-

( // take and double assignment

printf(" \n k=%d s=%f ", k, s);

printf("\n ANSWER: s=%f, Press any key...",s);

Options for individual assignments

Write a program to determine a table of function values at in an arbitrary range [ a,b] argument changes X with arbitrary steps h. Values a, b, h entered from the keyboard. The table must contain the following columns: sequence number, argument value x, function value, message about increasing or decreasing function, difference of two adjacent function values.

Determine the maximum and minimum values ​​of the function.

1. a=-p; b=p; h=0.4.

2. a=0.7; b=1.8; h=0.1.

3. a=-0.5; b=2.5; h=0.2.

4. a=-0.9; b=2.7; h=0.3.

5. a=-2; b=0.8; h=0.2.

6. a=-1.9; b=2.7; h=0.3.

7. a=-0.4p; b=0.4p; h=0.5.

8. a=-0.3p; b=1.3p; h= p/10.

9. a=-p/2; b= p/2; h=p/10.

10. a=-3; b=3; h=0.5.

“Programming cyclic computing processes”

Goal of the work: mastering methods for compiling algorithms for cyclic computational processes and organizing cyclic programs of complex structure.

Theoretical part

4.1.1. Cyclic algorithms.

A cycle is a sequence of actions that can be performed more than once.

A round-robin algorithm is an algorithm that contains one or more loops.

There are 3 types of cycles:

Loop with precondition;

Loop with postcondition;

Loop with a counter (counting loop).

If the execution of a loop is associated with some logical condition, then loops with a precondition or a postcondition are used.

Counter loops are a class in which the execution of the loop body must be repeated a predetermined number of times.

Block diagrams of cyclic algorithms look like this:

1. Loop with a counter.

2. Loop with precondition. 3. Loop with postcondition.

4.1.2 Loop operators in the C++ programming language.

In C++, for each type of loop there is a corresponding operator:

Loop like while (with precondition);

Loop like do...while (with postcondition);

Loop like for (counting).

1.Loop operator like while

Entry form:

while (condition) statement;

where: (condition) – logical expression;

operator – the operator or body of the loop executed in a loop.

If the body of the loop is a compound statement, then it must be enclosed in operator brackets (...):

while (condition)

group of operators

The scheme of how such a loop works: while the condition is true, the body of the loop is executed and the condition is checked again, etc. When the condition becomes false, the loop exits.

2. Loop operator like do...while

Entry form:

operator;

while(condition);

The scheme of how such a loop works: first the operator is executed, then the condition is checked, if the condition is true, the operator is executed and the condition is checked again, etc. When the condition becomes false, the loop exits.

If the body of the loop is a compound statement, then, as for a loop with a precondition, it must be enclosed in operator brackets (...):



group of operators

while(condition);

3. Loop operator like for

Entry form:

operator;

A is an initial expression that specifies initial values ​​for the loop parameter and, if necessary, initial values ​​for other parameters. For example:

i=0, x=0.5, p=1, s=0

B is a conditional expression that checks the condition for continuing the loop. For example:

C is an increment expression that specifies the increment of the loop parameter and, if necessary, other parameters, then they are written in a list. For example: x+=0.1, i++

4.1.3 An example of compiling an algorithm and program in C++ for a cyclic computing process.

Calculate the value of an expression:

b– initial value, its value is entered from the keyboard and does not change;

a– changes in the range in steps of 1;

y– result, its values ​​are displayed on the screen.

Based on the specification, variable a is an integer, so it can be used as a counter in a counting loop.

The block diagram of the algorithm for solving this problem using a counting cycle is as follows:

#include

#include

#include

printf("Enter b: ");

scanf(“%f”,&b);

printf(“a y\n”);

for (a=0;a<=10;a++)

printf(“%3d”,a);

printf(“%8.2f\n”,y);

y=(a-b)/sqrt(a);

printf(“%8.2f\n”,y);

The block diagram of the algorithm for solving this problem using a loop with a precondition is as follows:

The text of the C++ program corresponding to this algorithm is as follows:

#include

#include

#include

printf("Enter b: ");

scanf(“%f”,&b);

printf(“a y\n”);

printf(“%3d”,a);

printf(“%8.2f\n”,y);

y=(a-b)/sqrt(a);

printf(“%8.2f\n”,y);

else printf(“ y does not exist\n”);

The block diagram of the algorithm for solving this problem using a loop with a postcondition is as follows:

The text of the C++ program corresponding to this algorithm is as follows:

#include

#include

#include

printf("Enter b: ");

scanf(“%f”,&b);

printf(“a y\n”);

printf(“%3d”,a);

printf(“%8.2f\n”,y);

y=(a-b)/sqrt(a);

printf(“%8.2f\n”,y);

else printf(“ y does not exist\n”);

while(a<=10);

Practical part

4.2.1 Requirements for performing the work:

Complete the task from laboratory work No. 3 for a range of values ​​of one of the variables. The variable being changed, its range of change and step are indicated in Table 4. Create block diagrams of algorithms and programs for the two types of cycles specified in the individual task (Table 4).

Formalize the output of the results in such a way that the values ​​of the variable parameter are clearly highlighted and for each specific value, the values ​​of the result (three variables from column 2 of Table 3) are displayed in the form of a table.

The order of work.

1. Perform an analysis of the task, formulate a statement of the problem.

2. Create block diagrams of algorithms.

3. Create a program in C++. Provide input of initial data from the keyboard and output of results to the screen.

4. Check the functionality of the program on various initial data.

5. Analyze the results obtained.

Options for individual assignments.

Options for individual assignments are selected from Table 4 in accordance with the student number in the group list in the teacher’s journal.

Table 4. Options for individual tasks

No. Mutable Variable Types of cycles
10 ≤ a ≤ 10,Δ a=1
-4 ≤ d ≤ 4, Δ d = 0.5
-6 ≤ x ≤ 3, Δ x = 0.5
0 ≤ b ≤ 3 0, Δ b = 1.5 1. With precondition, 2. Countable
-15 ≤ j ≤ 1 0, Δ j = 0.5 1. With precondition, 2. With postcondition
5 ≤ e ≤ 35,Δ e = 2 1. Countable, 2. With postcondition
-5 ≤ m ≤ 15,Δ m = 1 1. With precondition, 2. Countable
1 ≤ c ≤ 70,Δ c = 3 1. With precondition, 2. With postcondition
1.5 ≤ c ≤ 15,Δ c = 0.5 1. Countable, 2. With postcondition
-8 ≤ b ≤ 28,Δ b = 2 1. With precondition, 2. Countable
-4.5 ≤ x ≤ 11.5,Δ x = 0.5 1. With precondition, 2. With postcondition
-7 ≤ k ≤ 2,Δ k = 0.3 1. Countable, 2. With postcondition
-1 ≤ m ≤ 21,Δ m = 1 1. With precondition, 2. Countable
-2 ≤ e ≤ 34,Δ e = 2 1. With precondition, 2. With postcondition
-11 ≤ c ≤ 23,Δ c = 2 1. Countable, 2. With postcondition
-13 ≤ p ≤ 50,Δ p = 3 1. With precondition, 2. Countable
3.3 ≤ b ≤ 9.3,Δ b = 0.3 1. With precondition, 2. With postcondition
3.5 ≤ y ≤ 12.3,Δ y = 0.4 1. Countable, 2. With postcondition
-7.5 ≤ a ≤ 5.7,Δ a = 0.6 1. With precondition, 2. Countable
-1.5 ≤ h ≤ 1.2,Δ h = 0.1 1. With precondition, 2. With postcondition
0 ≤ h ≤ 10,Δ h=0.5 1. Countable, 2. With postcondition
-15 ≤ b ≤ 15, Δ b =2 1. With precondition, 2. Countable
-7 ≤ l ≤ 3, Δ l = 0.5 1. With precondition, 2. With postcondition
-5.5 ≤ b ≤ 6.5, Δ b = 0.5 1. Countable, 2. With postcondition
1 ≤ k ≤ 9, Δ k = 0.4 1. With precondition, 2. Countable
0 ≤ b ≤ 6.9,Δ b = 0.3 1. With precondition, 2. With postcondition
-3 ≤ v ≤ 9,Δ v = 0.6 1. Countable, 2. With postcondition
-2 ≤ p ≤ 2.6,Δ p = 0.2 1. With precondition, 2. Countable

4.3 Test questions and practical tasks:

1. How does the while statement work?

2. How does the do ... while statement work?

3. How does the for statement work?

4. Underline the statements in the program that form a cycle.

5. What is the difference between the while and do ... while statements?

6. Replace one loop operator in the program with another.

In programming, we often encounter problems that involve processes that repeat themselves. Therefore, we must know and be able to use such a concept as “ cyclic computing processes».

It will be easy for a novice programmer to understand them using a generalized example. Moreover, it is important to understand that in all programming languages ​​there are ways to implement loops.

What is a loop in programming?

A cycle - in programming, is the repeated repetition of the same actions or calculations, but according to the same dependencies with different values ​​of the variables.

We encounter the concept of a cycle not only in programming. There are cycles in many areas of our lives.

For example, the water cycle in nature is a natural cycle in our lives.

Now let's look at the general rules and concepts used in computational cycles.

Stages of the cyclic process

In general, the cycle should be implemented in 4 stages:
  • Stage 1 – preparation of the cycle (initialization).
    Setting the initial value for the parameter and loop variable.
    Loop parameter– this value that counts the number of steps of the cycle (the number of repetitions of the cycle).
    Loop variable is a quantity that changes its value at each stage of the cycle.
    Initialization– this is setting the initial values ​​for the parameter and loop variable.
  • Stage 2 – body of the cycle.
    This is repeated repetition of an action in a cycle or calculations based on the same mathematical dependencies with different values ​​of variables.
  • Stage 3 – modification (change) of the cycle.
  • Stage 4 – cycle management.
    This is a condition check for continuation or start of the loop.
There are 3 loop operators in pascal that can implement any algorithmically – cyclic structure :
  1. Loop statement with parameter
  2. Loop operator with precondition
  3. Loop operator with postcondition
We will look at them in detail in the following article.

1. Methods for constructing cyclic computational processes in programs.

2. Entered into the computerNreal numbers. Write a program that displays the arithmetic mean of this set.

Introduction

Cyclic programs are used in almost any software. In this case, cycles can be explicit or implicit. In particular, the implicit loop is present in interrupt handlers, which effectively run in an infinite loop whose body is triggered by the interrupt. Subroutines - window functions of Windows applications - are also cyclic. Below we consider programs with a loop whose body contains functional modules.

Cyclic process is a computational process in which calculations are performed repeatedly using the same formulas for different values ​​of the argument.

Programs, implementing a cyclic process are called cyclic programs.

The organization of the cycle can be divided into the following stages:

preparation (initialization) of the cycle (AND);

performing loop calculations (loop body) (T);

modification of parameters (M);

checking the cycle end condition (U).

The order of these steps, such as T and M, may vary. Depending on the location of the cycle end condition check, a distinction is made between cycles with lower and upper endings. For a bottom-terminating loop, the body of the loop is executed at least once because the calculations are performed first and then the condition for exiting the loop is checked.


In the case of a top-ending loop, the body of the loop may not be executed even once if the exit condition is immediately met.

A cycle is called deterministic if the number of repetitions of the loop body is known or determined in advance. A cycle is called iterative if the number of repetitions of the loop body is unknown in advance, but depends on the values ​​of the parameters (some variables) involved in the calculations.

Loop Body- This is a repeatedly repeated section of the program.

Loop parameter is a variable that takes on new values ​​each time the loop is repeated (loops can be simple or complex).

General view of the loop n times

In general, a loop n times is written like this:

nc number of repetitions times

The service word nts (beginning of the cycle) and kts (end of the cycle) are written strictly one below the other and connected by a vertical line. To the right of this line, a repeatable sequence of commands (loop body) is written.

The number of repetitions is an arbitrary integer.

When executing the algorithm, the sequence of commands in the body of the loop is repeated the specified number of times. The rules of the algorithmic language allow specifying any integer number of repetitions. It can be zero or even negative. These cases are not considered erroneous, the body of the loop will simply not be executed even once, and the computer will immediately proceed to execute the commands written after cc

General view of the cycle so far

In general, the cycle is currently written as follows:

no condition yet

| loop body (sequence of commands)

When performing a cycle, the computer repeats the following actions:

a) checks the condition written after the function word while;

b) if the condition is not met, then the execution of the loop ends and the computer begins to execute the commands written after cc. If the condition is met, then the computer executes the body of the loop, checks the condition again, etc.

General view of the cycle for

nc for i from i1 to i2

| loop body (sequence of commands)

Here i is the name of an integer type value, i1, i2 are arbitrary integers or expressions with integer values. The body of the loop is executed sequentially for i = i1, i = i1 + 1, i1 + 2, …i = i2.

The rules of the algorithmic language allow specifying any integers i1, i2. in particular, i2 can be less than i1. this case is not considered an error - simply the body of the loop will not be executed even once, and the computer will immediately proceed to executing the commands written after cc.

Loop n times and loop while

Loops n times and so far are formatted in almost the same way in the algorithmic language. This is not surprising, because both of these commands define a loop - a repeating sequence of commands. The service words nts and kts indicate that a loop is being executed, and the loop header specifies the specific mechanism for its execution.

However, these two cycles have one significant difference. When the computer starts executing a loop n times, it knows how many times it will have to repeat the body of the loop. When executing a loop, this is not yet the case: the computer checks the condition of the loop each time and cannot determine in advance when execution will end. For now, you can find out the number of repetitions of a cycle only after the cycle is completed.

This makes it clear in which cases which loop should be used. If the number of repetitions is known by the time the loop starts, it is convenient to use the loop n times. If the number of repetitions cannot be determined in advance, a cycle is necessary.

For example, an automatic control program has the structure shown in Fig. 1. Modules included in the cycle(as well as interrupt handling modules), with one input and one output each, typically have the characteristic feature that the modules contain static variables that are assigned a value in the current cycle, and the analysis of these variables is performed in the next cycle. Thus, the mentioned variables characterize the state of the module at the end of the current or the beginning of the next program cycle. In what follows, we will consider only such modules of cyclic programs and denote them briefly as MCP.


Fig.1. Typical structure of a control program with an infinite loop.

MCPs have a varied structure, the complexity of which must be assessed according to special criteria. V.V. Lipaev proposed a convenient and objective criterion for the complexity of software modules, namely: the number and total length of paths in the control graph of the module. Only conditional and selection statements are taken into account. However, this criterion is clearly not enough for an MCP with static memory, because when analyzing an MCP it is necessary to remember the values ​​of all static variables set in the previous cycle. In addition, there are no recommendations for the standardization of algorithms and programs, except for the long-known structured programming in commonly used programming languages ​​such as C and Pascal. This article proposes to fill these gaps in relation to MCP.

2. Fragments of cyclic program modules

A two-terminal fragment, or simply a fragment, will be considered a section of a program with one input and one output (including loop operators) under the assumption that the MCPs under consideration are structured. The simplest fragment includes a single statement. A sequence of fragments is also a fragment. The MCP, in turn, is a fragment and consists of a sequence of fragments.

The method of independent fragments is proposed for synthesizing the structure of modules that implement decision tables. In this case, a fragment that can be inserted anywhere in the sequence of module fragments is considered independent. The independence of the location of such a fragment is due to the fact that the data analyzed in it is not generated in the specified sequence of fragments, and the data generated in the independent fragment is not analyzed in this sequence of fragments. Therefore, independent fragments can be executed in parallel (pseudo-parallel). In Fig. Figure 2 shows possible implementation options for a module with two independent fragments. In options “a” and “b” the fragments are rearranged without distorting the essence of the program; in option “c” the fragments are implemented in parallel.


Fig.2. Options for implementing a module with independent fragments:

a) and b) - sequential implementation,

c) - parallel implementation: a double horizontal line indicates parallelization of the program, a thick horizontal line indicates the completion of parallel processes.

A dependent fragment is one whose location depends on the location of another fragment(s) in the module. We will distinguish between above- and below-dependent fragments. The top-dependent fragment must always be located below some fragment in which the variables used in this (dependent) fragment are formed. A bottom-dependent fragment should always be placed above a fragment that uses variables generated in this fragment. Two dependent fragments, one of which is dependent from above on the second, and the second from below dependent on the first, will be called mutually dependent fragments. They cannot be interchanged and cannot be implemented in parallel. In Fig. Figure 3 shows an example of a module with mutually dependent fragments. Between mutually dependent fragments there may be others, dependent or independent of them. Fig.3. Module with dependent fragments.

We will call a dependent fragment whose location in the module is strictly defined as fixed. For example, in the module for recognizing a character entered from the keyboard, the first must be the bottom-dependent fragment of the actual character input. The “start” and “end” operators of a module are fixed fragments.

Absolutely independent fragments do not exist, if only because in any module there are the mentioned fixed fragments of the beginning and end. Therefore, an independent fragment, in general, has a possible location area limited by two mutually dependent fragments. That is, a more strict definition of an independent fragment is as follows: independent with respect to two fixed fragments we will call a fragment that can be placed anywhere in the sequence of fragments bounded above and below by the specified fixed fragments.




Top