How to draw a block diagram of parallel algorithms. “VBA Algorithm Development. Block diagram. Algorithm structures

It is extremely important to use the language of flowcharts when developing an algorithm for solving a problem. The solution to the same problem can be implemented using various algorithms that differ from each other both in calculation time and volume of calculations, and in their complexity. Recording these algorithms using flowcharts allows you to compare them, select the best algorithm, simplify, find and eliminate errors.

Refusal from the flowchart language when developing an algorithm and developing the algorithm directly in a programming language leads to significant loss of time and to the choice of a suboptimal algorithm. Therefore, it is necessary to initially develop an algorithm for solving the problem in the language of flowcharts, after which the algorithm is translated into a programming language.

When developing an algorithm for a complex problem, the method of step-by-step detailing is used. At the first step, the general structure of the algorithm is thought out without detailed elaboration of its individual parts. Blocks that require detail are outlined with a dotted line and are thought through and detailed in subsequent steps of developing the algorithm.

In the process of developing an algorithm for solving a problem, the following stages can be distinguished:

  • Stage 1. Mathematical description of the solution to the problem.
  • Stage 2. Definition of input and output data.
  • Stage 3. Development of an algorithm for solving the problem.

Basic algorithmic designs

In programming theory it has been proven that to write any algorithm, no matter how complex, it is enough three basic structures:

  • following (linear algorithm);
  • branching (branching algorithm);
  • loop-bye (round-robin algorithm).

Linear algorithms

Linear algorithm is formed from a sequence of actions following one after another. For example, to determine the area of ​​a rectangle, you must first set the length of the first side, then set the length of the second side, and only then use the formula to calculate its area.

Example

TASK. Develop an algorithm for calculating the hypotenuse of a right triangle using the known values ​​of the lengths of its legs a and b.

Using this problem as an example, we will consider all three stages of developing an algorithm for solving the problem:

The mathematical solution to the problem is the well-known formula:

,

where c is the length of the hypotenuse, a, b are the lengths of the legs.

The input data is the values ​​of legs a and b. The output is the length of the hypotenuse – c.

Branching Algorithms

contains a condition, depending on which a particular sequence of actions is performed.

Example

TASK. Develop an algorithm for calculating the largest number from two numbers x and y.

Stage 1. Mathematical description of the solution to the problem.

From the mathematics course it is known that if x > y, then the greatest number x, if x< y, то наибольшее число y, если x = y, то число x равно числу y.

Stage 2. Determination of input and output data.

The input data is the values ​​of the numbers x and y. The output is:

  • greatest number
  • any of the numbers if the numbers are equal

To solve the problem we need to know the values ​​of x and y.

Stage 3. Development of an algorithm for solving the problem.

In the diagram of the algorithm for solving the problem, the numbers of the elements of the algorithm are indicated in numbers, which correspond to the numbers of steps in the verbal description of the algorithm

In the algorithm under consideration (Fig. 3) there are three branches of solving the problem:

  • first: these are elements 1, 2, 3, 4, 8.
  • second: these are elements 1, 2, 3, 5, 6, 8
  • third: these are elements 1, 2, 3, 5, 7, 8.

The choice of branch is determined by the x and y values ​​in elements 3 and 5, which are conditions that determine the order in which the elements of the algorithm are executed. If the condition (equality) written inside the “solution” symbol is satisfied for the entered values ​​of x and y, then elements 4 and 8 are executed next. This follows from the fact that they are connected by a line labeled “yes” and the direction (sequence) of calculations is indicated arrow.

If the condition in element 3 is not met, then element 5 is executed next. It is connected to element 3 by a line labeled “no”. If the condition written in element 5 is met, then elements 6 and 8 are executed, otherwise elements 7 and 8 are executed.

Cyclic algorithms

determines the repetition of some part of the actions (operations) until a condition is violated, the fulfillment of which is checked at the beginning of the cycle. A set of operations performed repeatedly is called the body of a loop.

Algorithms in which individual actions are repeated many times are called cyclic algorithms, The set of actions associated with repetition is called cycle.

When developing a cyclic structure algorithm, the following concepts are distinguished:

  • cycle parameter – a value whose value changes when repeating the cycle;
  • initial and final values ​​of the cycle parameters;
  • cycle step – the value by which the cycle parameter changes with each repetition.

The cycle is organized according to certain rules. A cyclic algorithm consists of a loop preparation, a loop body, and a loop continuation condition.

Cycle preparation includes actions related to setting initial values ​​for cycle parameters:

  • initial values ​​of the cycle;
  • loop end values;
  • cycle step.

The body of the loop includes:

  • repeated actions to calculate the required quantities;
  • preparing the next loop parameter value;
  • preparation of other values ​​necessary for repeated execution of actions in the body of the loop.

The cycle continuation condition determines the permissibility of performing repeated actions. If the loop parameter is equal to or greater than the end value of the loop, then execution of the loop must be terminated.

Example

TASK. Develop an algorithm for calculating the sum of natural numbers from 1 to 100.

Stage 1. Mathematical description of the solution to the problem.

Let us denote the sum of natural numbers by S. Then the formula for calculating the sum of natural numbers from 1 to 100 can be written as follows:

where Xi is a natural number X with number i, which varies from 1 to n, n=100 is the number of natural numbers.

Stage 2. Determination of input and output data.

The input data are natural numbers: 1, 2, 3, 4, 5, …, 98, 99, 100.

Output– the value of the sum of the terms of a sequence of natural numbers.

Loop parameter a value that determines the number of repetitions of the cycle. In our case, i is the number of a natural number.

Cycle preparation consists in setting the initial and final values ​​of the loop parameter.

  • the initial value of the loop parameter is 1,
  • the final value of the loop parameter is n ,
  • The loop step is 1.

For correct summation, you must first set the initial value of the sum to 0.

The body of the loop. In the body of the loop, the value of the sum of numbers will be accumulated, and the next value of the loop parameter will be calculated using the formulas:

Condition for continuing the loop: the cycle must be repeated until the last member of the sequence of natural numbers is added, i.e. until the loop parameter is less than or equal to the final value of the loop parameter.

Stage 3. Development of an algorithm for solving the problem.

Let us introduce the following notation: S is the sum of the sequence, i is the value of the natural number.

The initial value of the cycle is i=1, the final value of the cycle is i =100, the cycle step is 1.

Verbal description of the algorithm Writing an algorithm in flowchart language
  1. The beginning of the algorithm.
  2. Cycle preparation: S:=0; i=1; n= 100;
  3. Checking the condition. If i<=n , то перейти к шагу 4, иначе к шагу 6.
  4. Accumulation of the amount: S:=S+i;
  5. Calculation of the next value of the loop parameter: i:=i+1;
  6. Information output: sum of natural numbers – S.
  7. End of the algorithm.

In the diagram of the algorithm for solving the problem, the numbers of the elements of the algorithm are indicated in numbers. The numbers of elements correspond to the numbers of steps in the verbal description of the algorithm.

A flowchart is a graphical model that describes processes or algorithms, where the steps are blocks of various shapes, and they are connected by lines. And these lines show the direction of the sequence. How the block diagram should be executed is regulated by the standard. And it serves so that a programmer or a person who does not have knowledge in this area can clearly see how a program or process works. Flowcharts are often created by programming professionals.

Why does a programmer need a flowchart?

FlowChart notation is the fastest, most versatile and accessible method by which a programmer can explain to a non-specialist how any process is performed or a program works. A block diagram also represents documentation for any program. If a programmer needs to explain how a simple utility or small code works, he can clearly demonstrate this using a regular graphics editor. But if the program is complex, its code consists of many modules and lines, a simple editor will not work. In this case, programmers use professional solutions and build a flowchart based on the source code.

Programs and online services for constructing block diagrams

You can use special programs that run on your computer, or services that offer real-time construction of any circuit using Pascal, Delphi, and even C++. Experienced programmers prefer to use only computer programs.

Services that are provided for online process mapping often do not support the necessary requirements and therefore cannot guarantee correct operation. For example:

  • A number of programming language commands are not supported and, therefore, the sequence diagram of actions is not constructed correctly.
  • The graphs showing the sequence of operations are poorly drawn.
  • The online service often does not allow you to save the flowchart in the required format.
  • And these are not all the disadvantages of such services.
Special computer applications handle the task of constructing flowcharts much more professionally. Well, for those who do not want to install programs on their computer, we recommend using the software interface for creating charts and graphs Chart API from Google.


FCeditor is a convenient application that supports the programming languages ​​C++ (.cs file), Delphi, Pascal (.pas file). If you need to edit a code file in this program, you must import it first. When FCeditor parses the imported .pas or .cs file, it will display a class tree on the left, a tab will appear in the panel, and in it will be the program code and diagrams.

Important note! You can export the constructed graph or diagram to any format: from jpeg and tiff to png and bmp. The program has Russian-language support and a simple user interface.


Another simple program with a minimalist design but wide functionality. The user interface, similar to the previous program, is simple and convenient even for non-professionals. In the main window you will see three fields. In the first field, the code is presented in a tree form, in the second - the text itself, and in the third, largest, you will see a constructed diagram or graph. This application is convenient to use because of the backlight. Elements of the code, tree structure, and diagram are not only highlighted, but also collapsed.

The diagram created in the Autoflowchart program can be exported not only to graphic format, but also to xml files. This program is also a convenient code editor. Anything you edit in code is instantly displayed in the diagram. Autoflowchart supports any programming language.


Code Visual to Flowchart version 6.0 is the most powerful computer program used by professionals to create charts and graphs. It is distinguished by extensive functionality and the ability to build an accurate circuit. Despite the sophisticated functionality and capabilities, the program has a convenient user interface. In the main window you will see three fields. There are two tabs on the left: one shows the structure of the project, the other shows the structure of classes. In the center of the main window you will see the program code, and on the right - a diagram of the code segment.

You can export the constructed diagram into only two formats: png and bmp.

Important note! All these programs are great solutions to help you create clear flowcharts that meet standards. But to use each of the programs discussed above, you will have to pay. The trial version provides only a small part of the functionality and is therefore suitable for evaluation purposes only.


Often, application development begins with building a flowchart. Before you create a program code, you need to think it through and draw up a diagram of the sequence of actions. And this is the scheme on the basis of which the programmer then writes code.

For those who are accustomed to using online services, we recommend two proven ones - Chart from Google and Draw.io


Draw.io is a convenient service in which you can build and edit flowcharts. Its extensive functionality, user-friendly interface and package of tools allow you to edit, format and modify blocks, creating them according to a standard scheme or an individual one. You can also use external images when creating a diagram. The finished diagram can be saved in graphic, vector formats, or as a document on cloud storage, or downloaded to your computer.

Draw.io will appeal to novice programmers for its rich functionality and ease of use. And what’s important is that you can use it absolutely free.

Google's Chart API perfectly visualizes any code and creates graphs, charts and charts. An extensive toolkit is represented by plug-in libraries, with the help of which high-quality graphs and diagrams are created. Google's service has a huge variety of schemes in its functionality, with the help of which not only programs are created, but also websites and documents.


To use this powerful online service, you only need to read the detailed instructions and have minimal knowledge. How to properly use all the service library tools from Google is shown in the document package.


Google's Chart API is a great tool for professional programmers.








Back forward

Attention! Slide previews are for informational purposes only and may not represent all of the presentation's features. If you are interested in this work, please download the full version.

Lesson objectives.

Educational - systematization of knowledge, skills and abilities on the topic “Algorithms and performers”; practicing skills in drawing up algorithms and presenting them in the form of flowcharts.

Educational – increasing student motivation, developing skills of self-organization, independence and initiative.

Developmental – development of figurative, logical thinking of students; ability to analyze and synthesize knowledge; formation of information culture among students.

Equipment: computer, projector, screen, presentation.

DURING THE CLASSES

I. Organizational moment (slides 1, 2).

II. Updating basic knowledge (slides 3, 4, 5). What is an algorithm?

  • List the properties of the algorithm.
  • Name the types of algorithms.
  • What is a linear algorithm.
  • What is a branching algorithm?
  • What is a round robin algorithm?
  • What types of cyclic algorithm do you know?
  • Name ways to present the algorithm.
  • Which of the following figures are used in block diagrams?
  • 10. Based on these block diagrams, name the type of algorithm.

    linear

    loop with precondition

    branching (full form)

    loop with postcondition

    branching (incomplete form)

    loop with parameter

    III. Problem solving

    Teacher: Now we move on to solving problems. Today we will build block diagrams with you.

    Task 1. Determine the distance traveled by a person if the time, speed of movement, and the movement were uniform are known. (Slide 6)

  • Guys, what do we know from the problem statement? ( Speed, time, movement was uniform, which means we calculate the distance using the formula S=v*t)
  • What should you and I do before building a flowchart? (Create an algorithm)
  • Let's verbally compose a verbal algorithm.
  • Algorithm

    1. Enter v, t.

    2. Calculation of s.

    3. Conclusion s.

    • Tell me, what algorithm did we get? ( Linear algorithm)
    • Now let's move on to building a block diagram. What flowchart elements do we need? ( Start, end, data entry, distance calculation, result output) all elements on the screen.
    • Guys, put all the elements in the right order. ( The result is on the screen)

    Calculate (slide 7).

    • Where do we start? (Create a verbal algorithm)
    • What should you pay attention to in this task? (We calculate the value of the fraction; the denominator contains the difference 7-y, which, depending on the value of y, may be equal to zero, in this case there will be no solution)

    Algorithm

    1. Enter a, y.

    2. If 7-y=0, then there is no solution.

    4. Conclusion s.

    • Tell me, what algorithm did we get? (Branching algorithm, full form)
    • Guys, look at each point of the algorithm and tell me which elements of the flowchart correspond to them. (On the screen the figures are individual)
    • What flowchart elements are we missing? ( Beginning, end)
    • Guys, help me build a flowchart, naming the elements in order. (Elements appear on the screen one by one.)

    Task 3. Construct a flowchart of the algorithm for signing 10 New Year cards. (Slide 8)

    Students write down a verbal algorithm in a notebook, a check is carried out (the answer is on the screen), then they build a flowchart, and a check is carried out (the answer is on the screen).

    IV. Summing up the lesson

    V. Homework

    For problem 3, create flowcharts using a loop with a precondition and a postcondition.

    To visualize the stages of any process, it is convenient to use flowcharts. They allow you to present a logical chain in the form of separate graphic elements combined in the desired order.

    A great way to quickly make a flowchart is to use special online programs. Let's look at how they work and what features they have using the example of three Russian-language editors.

    How to draw a beautiful diagram inCanva

    We have already talked about the Canva website many times in our articles. This one is ideal for creating infographics, presentations, posters, outdoor advertising, etc. Today we’ll talk about how Canva will help you build a flowchart online.

    To begin with, it’s worth saying that of all the services that we will consider today, this is the only resource that allows you not only to create a clear and structured diagram, but also to design it beautifully. The site is intended more for designers than for mathematicians or programmers, so if you need, for example, to create a colorful diagram for presenting a project or marketing plan, then Canva is definitely the best assistant.

    First, choose the template you like among dozens of different options.

    Conveniently, most of the layouts here are provided for free.


    You can customize absolutely everything here: from the font of the inscriptions to the structure of the image


    In addition, it is possible to add beautiful diagrams


    This section also has a function for inserting the created image onto your Internet resource. You just need to copy the code snippet with the diagram and paste it into your blog or website

    When work on the flowchart is completed, click “Download”.


    Selecting the file format

    One of the big advantages of using Canva is that the image is ultimately saved without any watermarks.

    Convenient construction of logical chains withDraw. io

    Another free online service worthy of your consideration is Draw.io. It is considered one of the most famous sites for creating diagrams, diagrams, graphs and structures. Here, just like in Canva, it is possible to connect a Russian-language interface, which greatly simplifies the process.

    Before starting work, we are asked to choose a place to save the finished result, as well as decide on the layout.


    Thanks to Draw.io for the convenient structuring of the templates - they are all divided into categories, which allows you to choose the right option as quickly as possible

    Let's move on to editing. To change an element, simply click on it with the mouse, after which the style, text and layout characteristics are displayed on the right.


    Compared to the previous service, the settings here seem a little primitive, but nevertheless all the necessary parameters are present

    To replace a shape, select a suitable object in the left panel and drag it to the desired location. It’s convenient that when you move elements, all the arrows attached to them automatically change their position.


    It is also possible to insert a ready-made diagram or other image into the document by importing it from a computer, cloud storage or online resource

    To save the result, click “File” - “Save As”, after which we are offered the following options:

    • Google Drive;
    • OneDrive;
    • Dropbox;
    • GitHub;
    • Trello;
    • computer;
    • browser.

    The finished file is downloaded in .xml format.

    Google chart – a powerful tool for developers

    Finally, our list of recommendations ends with the Google chart API. It is a library of code snippets that, when embedded, appear on your website to create beautiful charts, graphs, structures, tables, etc.


    Select the desired category
    Using the example, we see what the diagram will look like if we do not change the main essence of the code

    After copying and pasting into our website, we need to enter the appropriate data instead of the ones given in the example. This is not difficult, given that the code has many useful comments and clarifications.

    For experienced programmers, the Google chart API will become an indispensable assistant, because it offers a wide range of additional tools for effective visualizations. If you are not a very confident developer, you can use the standard options - they also look quite decent.

    All the programs we reviewed are completely different, so it is impossible to single out the most convenient one. It all depends on your goals and wishes. If you need to get a beautiful graphic product, then no site can do it better than Canva. If you need a minimalistic scheme without any special frills, Draw.io will come to the rescue. If you want to write code for your chart, use the Google chart API.

    If you need to create a flowchart without using the Internet, you can do it in Word 2016. The process will not be as convenient and fast as in the case of online programs, because There are no blanks or templates here. All elements and connections between them will have to be drawn from scratch, so be patient.

    This article will look at examples of flowcharts that you may encounter in computer science textbooks and other literature. A flowchart is an algorithm by which any task assigned to the developer is solved. First you need to answer the question of what an algorithm is, how it is represented graphically, and most importantly, how to solve it, knowing certain parameters. It should be immediately noted that there are several types of algorithms.

    What is an algorithm?

    This word was introduced into use by the mathematician Muhammad al-Khwarizmi, who lived in the period 763-850. He is the person who created the rules for performing arithmetic operations (and there are only four of them). But GOST from 1974, which states that:

    An algorithm is a precise prescription that defines a computational process. Moreover, there are several variables with given values ​​that lead the calculations to the desired result.

    The algorithm allows you to clearly indicate to the performer to carry out a strict task in order to solve the task and get the result. Developing an algorithm is breaking down one large task into a certain sequence of steps. Moreover, the developer of the algorithm must know all the features and rules of its compilation.

    Features of the algorithm

    In total, eight features of the algorithm can be distinguished (regardless of its type):

    1. There is a function for entering initial data.
    2. There is an output of a certain result after the completion of the algorithm. It must be remembered that the algorithm is needed in order to achieve a certain goal, namely, to obtain a result that is directly related to the original data.
    3. The algorithm must have a discrete type structure. It should be presented in sequential steps. Moreover, each next step can begin only after the completion of the previous one.
    4. The algorithm must be unambiguous. Each step is clearly defined and does not allow arbitrary interpretation.
    5. The algorithm must be finite - it must be executed in a strictly defined number of steps.
    6. The algorithm must be correct - it must provide an exclusively correct solution to the problem.
    7. Generality (or mass character) - it must work with various initial data.
    8. The time given to solve the algorithm should be minimal. This determines the effectiveness of solving the problem.

    And now, knowing what flowcharts of algorithms exist, we can begin to consider ways to write them. And there are not very many of them.

    Verbal recording

    This form is usually used when describing a procedure for a person: “Go there, I don’t know where. Bring something, I don’t know what.”

    Of course, this is a comic form, but the essence is clear. As an example, we can cite, for example, the usual writing on bus windows: “In case of an accident, pull out the cord and push out the glass.”

    Here a clear condition is set under which two actions must be performed in strict sequence. But these are the simplest algorithms; there are also more complex ones. Sometimes formulas and special designations are used, but under the obligatory condition - the performer must understand everything.

    It is possible to change the order of actions if you need to return, for example, to a previous operation or bypass some command under a certain condition. In this case, it is advisable to number the commands and be sure to indicate the command to which the transition occurs: “After finishing all the manipulations, repeat steps 3 to 5.”

    Recording in graphical form

    This recording involves flowchart elements. All elements are standardized, each team has a specific graphic entry. And a specific command must be written inside each of the blocks in ordinary language or mathematical formulas. All blocks must be connected by lines - they show the exact order of the commands being executed. Actually, this type of algorithm is more suitable for use in program code than a verbal one.

    Recording in programming languages

    If an algorithm is necessary for a problem to be solved by a program installed on a PC, then it must be written in special code. There are many programming languages ​​for this. And the algorithm in this case is called a program.

    Block diagrams

    A flowchart is a graphical representation of an algorithm. All commands and actions are represented by geometric shapes (blocks). Inside each figure is written all the information about the actions that need to be performed. Connections are shown as regular lines with arrows (if necessary).

    For the design of flowcharts of algorithms, there is GOST 19.701-90. It describes the procedure and rules for creating them in graphical form, as well as the basic methods for solving them. This article provides the basic elements of flowcharts that are used in solving problems, for example, in computer science. Now let's look at the rules of construction.

    Basic rules for drawing up a flowchart

    We can highlight the following features that any block diagram should have:

    1. There must be two blocks - “Start” and “End”. And in a single copy.
    2. Communication lines must be drawn from the initial block to the final block.
    3. All blocks except the final one should have flow lines coming out of them.
    4. All blocks must be numbered: top to bottom, left to right. The serial number must be placed in the upper left corner, making a break in the style.
    5. All blocks must be connected to each other by lines. They are the ones who must determine the sequence in which actions are performed. If the flow moves from bottom to top or from right to left (in other words, in the reverse order), then arrows are necessarily drawn.
    6. Lines are divided into outgoing and incoming. It should be noted that one line is outgoing for one block, and incoming for another.
    7. The flow line only goes out from the initial block in the diagram, since it is the very first.
    8. But the final block only has an input. This is clearly shown in the block diagram examples provided in the article.
    9. To make block diagrams easier to read, incoming lines are shown at the top and outgoing lines at the bottom.
    10. Discontinuities in flow lines are acceptable. They must be marked with special connectors.
    11. To make the flowchart easier, it is allowed to write all the information in the comments.

    Graphic elements of flowcharts for solving algorithms are presented in the table:

    Linear type of algorithms

    This is the simplest type, which consists of a certain sequence of actions; they do not depend on what data was entered initially. There are several commands that are executed once and only after the previous one has been completed. A linear block diagram looks like this:

    Moreover, connections can go both from top to bottom and from left to right. Such a block diagram is used to write calculation algorithms using simple formulas that have no restrictions on the values ​​of the variables included in the calculation formulas. Linear algorithm is an integral part of complex calculation processes.

    Branching Algorithms

    Block diagrams built using such algorithms are more complex than linear ones. But the essence does not change. A branching algorithm is a process in which what happens next depends on how a condition is met and what solution is obtained. Each direction of action is a branch.

    The diagrams depict blocks called “Solution”. It has two outputs, and a logical condition is written inside. The further movement according to the algorithm scheme depends on how it is performed. Branching algorithms can be divided into three groups:

    1. “Bypass” - in this case, one of the branches does not have operators. In other words, several actions on another branch are bypassed.
    2. “Branching” - each branch has a specific set of actions to perform.
    3. “Multiple choice” is a branch in which there are several branches and each contains a specific set of actions to be performed. Moreover, there is one peculiarity - the choice of direction directly depends on the given values ​​of the expressions included in the algorithm.

    These are simple algorithms that can be solved very easily. Now let's move on to more complex ones.

    Round robin algorithm

    Everything here is extremely clear - a cyclic block diagram represents an algorithm in which similar calculations are repeated many times. By definition, a cycle is a specific sequence of actions performed repeatedly (more than once). And there are several types of cycles:

    1. In which the number of repetitions of actions is known (they are also called cycles with a counter).
    2. For which the number of repetitions is unknown - with a postcondition and a precondition.

    Regardless of what type of loop is used to solve the algorithm, it must have a variable with which the output occurs. It determines the number of repetitions of the cycle. The working part (body) of the cycle is a certain sequence of actions that is performed at each step. Now let’s take a closer look at all the types of loops that can be encountered when creating algorithms and solving problems in computer science.

    Loops with counters

    The figure shows a simple block diagram in which there is a loop with a counter. This type of algorithm shows that the number of repetitions of a given cycle is known in advance. And this number is fixed. In this case, the variable that counts the number of steps (repetitions) is called a counter. Sometimes in textbooks you can find other definitions - a loop parameter, a control variable.

    The block diagram very clearly illustrates how a counter loop works. Before you begin the first step, you need to assign an initial value to the counter - this can be any number, it depends on the specific algorithm. In the case when the final value is less than the counter value, a certain group of commands that make up the body of the loop will begin to be executed.

    After the body is executed, the counter is changed by the counter step value, denoted by h. If the resulting value is less than the final value, the cycle will continue. And it will end only when the final value is less than the loop counter. Only in this case will the action that follows the cycle be executed.

    Typically, flowchart notation uses a block called "Preparation". The counter is written in it, and then the following data is indicated: initial and final values, change step. In the block diagram these are the parameters I n, Ik and h, respectively. In the case when h=1, the step size is not recorded. In other cases, this is mandatory. A simple rule must be followed - the flow line must enter from the top. And the flow line that comes out from the bottom (or from the right, depending on the specific algorithm) should show the transition to the subsequent statement.

    Now you have fully studied the description of the block diagram shown in the figure. You can move on to further study. When using a loop with a counter, certain conditions must be met:

    1. The body is not allowed to change (force) the counter value.
    2. It is prohibited to transfer control from outside to the body operator. In other words, you can only enter a cycle from its beginning.

    Loops with precondition

    This type of cycle is used in cases where the number of repetitions is unknown in advance. A loop with a precondition is a type of algorithm in which, immediately before the execution of the body begins, a condition is checked under which the transition to the next action is allowed. Pay attention to how the elements of the flowchart are depicted.

    In the case when the condition is met (the statement is true), the transition to the beginning of the loop body occurs. It directly changes the value of at least one variable that affects the value of the stated condition. If you don't adhere to this rule, you'll end up with a loop. If, after the next check of the execution condition of the loop body, it turns out that it is false, then the exit occurs.

    In block diagrams of algorithms, it is allowed to check not the truth, but the falsity of the initial condition. In this case, the loop will exit only if the condition value turns out to be true. Both options are correct; their use depends on which one is more convenient to use to solve a particular problem. This type of loop has one feature - the body may not be executed if the condition is false or true (depending on the option that is used to solve the algorithm).

    Below is a flowchart that describes all these steps:

    What is a loop with a postcondition?

    If you look closely, this type of cycle is somewhat similar to the previous one. We will now try to construct a block diagram describing this cycle ourselves. The peculiarity is that the number of repetitions is unknown in advance. And the condition is set after the exit from the body has occurred. From this we can see that the body, regardless of the decision, will be executed at least once. For clarity, take a look at the block diagram describing the execution of the condition and operators:

    There is nothing complicated in constructing algorithms with loops; you only need to understand them once. Now let's move on to more complex structures.

    Complex Loops

    Complex ones are those structures that contain one or more simple loops inside them. Sometimes they are called nested. Moreover, those constructions that cover other cycles are called “external”. And those that are included in the design of external ones are internal. When each step of the outer loop is executed, the inner loop is completely scrolled, as shown in the figure:

    That's all, you have reviewed the main features of constructing flowcharts for solving algorithms, you know the principles and rules. Now we can look at specific examples of flowcharts from life. For example, in psychology such constructions are used to help a person solve a question:

    Or an example from biology to solve the problem:

    Solving problems with flowcharts

    Now let's look at examples of problems with flowcharts that can be found in computer science textbooks. For example, a block diagram is given according to which some algorithm is solved:

    In this case, the user independently enters the values ​​of the variables. Let's say x=16 and y=2. The execution process is as follows:

    1. The x and y values ​​are entered.
    2. The transformation operation is performed: x=√16=4.
    3. The condition is met: y=y 2 =4.
    4. The calculation is made: x=(x+1)=(4+1)=5.
    5. Next, the following variable is calculated: y=(y+x)=(5+4)=9.
    6. The solution is output: y=9.

    This example of a computer science flowchart clearly shows how the algorithm is solved. It is necessary to pay attention to the fact that the values ​​of x and y are specified at the initial stage and they can be anything.