# Chapter 8

Last edited by 8 years, 7 months ago

## DISPLAY OF CYCLES

 The success of a decision depends on the person’s ability to “visualize the problem situation”, visualize it and operate visual images. Natalia Zavalova Boris Lomov, Vladimir Ponomarenko

### NORMAL CYCLE

In the language of DRAGON has the following range of cycles:

• ordinary cycle;
• switching cycle;
• FOR loop;
• twig cycle;
• loop wait.

The first four-cycle considered in this chapter, the cycle of wait – in Ch. Eleven.

The composite visual operator “normal cycle” (Fig. 2, makroikona 4) contains icons of “question” and “loop the loop” (Fig. 1, icons I4, I24). It covers the three types of cycles (Fig. 34-36):

• cycle to (do-while),
• WHILE loop (while-do),
• Hybrid cycle (do-while-do).

Examples cycles to repent and are shown in Fig. 37, 38. Early exit from the cycle shown in Fig. 39-42. Construction “loop cycle” shown in Fig. 43-45.

Analyzing the figures, you will notice the following features.

• Operator “normal cycle” has one input and one or more outlets.
• Cycle single output represents skewer block (input and output are in the same vertical).
• If the cycle has more than one exit, the main exit is located on the main vertical extra – the right of it.
• Loop the loop is to the right of the main vertical and twisted counterclockwise.
• Icon “issue” sets the loop condition, which is divided into two parts: the conditions of continuation and termination condition (Fig. 37).
• Condition corresponds to the continuation of the right output icon “question”, the termination condition – lower.
• The condition can be marked as the end of the word “no” and the word “yes.” The same applies to extension condition.

### SWITCH and switch CYCLE

Suppose the algorithm need to organize branching into several directions. The problem can be solved in two ways: using the icons “issue” (Fig. 46a) and a switch (Fig. 46b).

Switch – a visual component operator (Fig. 2, the macro icon 3) having one input and one output, having one icon of “choice” and a few (two or more) icons “option” (Fig. 1, icons I5, u6) . Inside icon “choice” is the inscription, usually in the affirmative, which represents an issue of strictly defined number of responses (two or more). Answers written in icons “option.” Thus, the number of options equal to the number of responses. Formally speaking, the icon in the “choice” written variable in the icons “option” – its values. Fig. 46b variable “Traffic Light” takes three values: green, yellow, red.

The switch allows you to create a special type of cycle – switching cycle (Fig. 2, makroikona 5). To do this, pull the right arm of the output switch, bend it up and connect the arrow to the right place (Fig. 47).

Fig. 48 shows a cycle with a switch, but it is not the switching cycle, and the usual. How to tell them apart? In the first case, the switch has two outputs, the second – only one. There is another difference. If output is curled upward Icons “issue” – it is a regular cycle (DO WHILE, or hybrid). If the output switch is up – we are switching cycle.

### CYCLE FOR

Fig. 49 and 50 show two options to solve a simple problem matemati¬cheskoy. In the first case, a cycle before, the second – cycle for. Cycles for – visual component operator (Fig. 2, the macro icon 6) containing the icon “start cycle for” and “end of cycle for” (Fig. 1, the icons and 12, and 13), between which one or more other icons. Inside icon “start cycle for” indicates the loop variable, its initial and final value and the step. The procedure for recording these values ​​determined by the selected text option syntax. Fig. 50 illustrates an embodiment, the default is that the pitch is equal to 1.

### Twig CYCLE

Rings described above can be used in both primitive and in silhouette. In this section we will focus on twig cycle, which occurs only in silhouette.

Twig cycle is generated when the label is in the icon of the “address” indicates either a branch, or a branch, which is to the left. For example, the icon of the address “Buying buns” in Fig. 51 points to his branch. Within the cycle of browse may appear cycles of other types. Fig. 52 shows the construction of the “cycle in the loop”, which is located inside of browse cycle to cycle.

When replacing the primitive to the equivalent silhouette hybrid cycle often turns into a twig cycle. This is easily seen by comparing the equivalent algorithms in Fig. 41 and 53.

### The main route SILHOUETTE

In this section we continue the study of cycles twig and try to answer the question: how to find the main route of browse cycle? To do this, you need to analyze the concept of “the main route silhouette” (Fig. 54).

Linear (straight) has a silhouette of a single route, which is the main thing. He passes on a skewer all branches and all the icons silhouette (Fig. 54a).

The formula for the route silhouette has a singularity: the icon of the same name “address” and “branch name” refers to a single letter, which is repeated twice in the formula. For example, a silhouette in Fig. 54a has the formula

 ABEFGC – CHID – DJKM

where the paired letters denote the transition from the first to the second branch (C – C) and the second to the third (D – D).

The branch is called unicast, if it has one icon “address”. If all branches unicast silhouette considered unicast.

Line silhouette always unicast. However, unicast silhouette can be branched. In the latter case, its main route follows the skewer all the branches, but it does not go all the icons (Fig. 54b).

If at least one branch has more than one address, it may be a situation where some branches do not fall on the main route.Fig. 54B icon address D is for side route. This leads to the fact that the branch D is also provided on the secondary route.As a result, the main route passes through the skewer all the branches, except branch D (Fig. 54B).

Twig loops are formed only in multicast silhouettes, one-address them, in principle, can not be. They come in several types:

• odnovetochnye (if the loop is placed in one branch);
• dvuhvetochnye (if the cycle takes two branches);
• trehvetochnye (cycle in three branches), and so on. d.

How does odnovetochny cycle? Assume before the loop in Fig. 54g that the conditions

Assume also that the twig cycle performed twice, after which the condition E is set to “no.” This means that the third pass of the branch in the loop will exit the path “E No C”. In such a situation, the formula of the main route for the silhouette in Fig. 54g takes the form:

What is the main route to the dragon scheme? Response shows a thick line in Fig. 54g. We see that the main route as it branches out in the icon E and passes through both of its release. Of course, this convention, which means the following.At first (when E = yes) the main route is on a skewer, and then (when the condition E = end of the cycle is not) main route passes through the right output icon E.

To build odnovetochny cycle, you need the left icon “address” record X, where X – the name of the branch. To exit the loop should add a second icon of the “address” and write in it Y, where Y – the name of the following (in order of performance) branches.

If the twig cycle too many icons, it may not fit in one branch. Fortunately, it can be divided into parts. For example, a twig cycle in Fig. 54d has five icons: E, F, G, H, R (icon “branch name” and “address” does not count). Put icons E and F in branch B, and the icon G, H, R – in the branch C. As a result, the cycle will dvuhvetochnym. The main route silhouette with dvuhvetochnym cycle has a branch in the icon condition R. R = yes lets go back to the top of the cycle. R = If not, the main route leads us to the end of the algorithm (Fig. 54d).

Thus dvuhvetochny cycle – a cycle comprising two threads X and Y, wherein X is a branch icon address Y, and branch Y – icon address X.

Fig. 54e shows the situation “cycle in the loop”: the cycle C is a twig of browse inside the loop B. It can be seen that in this case the main route “branches” twice in the icons and R J.

If the condition R = yes, there is a repetition of the inner loop C. When combined conditions

 R = No J = Yes

made out of the loop and repeat With the outer loop B. Finally, a combination of conditions

 R = No J = No

It means that the loop B and the whole algorithm ends.

### CONCLUSIONS

1. In various text languages ​​in the description of cycles used different sets of keywords relevant to the different semantics. Confusion exacerbate differences in logic end of the cycle. For example, in C language for while loops, and do-while loop termination condition corresponds to false or 0, the continuation condition – true or 1. Pascal picture is different: in a loop while-do out of the cycle corresponds to the value false, and the cycle repeat-until, for some mysterious reasons applied diametrically opposite principle: a way out of the cycle is when the logical expression evaluates to true. All these confusing the programmer must know the rules and to abide scrupulously.
2. The lack of unification of keywords and inconsistency in the definition of the conditions out of the loop is a serious drawback: the programmers have to cram keywords and value terms, and development of each of the following new language requires cramming.
3. In terms of visual programming, these difficulties are far-fetched and easily eliminated. We only need to abandon existing habits and outmoded stereotypes of thinking associated with textual programming. Visualization of a qualitative change in the situation, since the text is no longer the only carrier of information.
4. Visual images reduce the burden on the programmer’s memory, eliminate errors caused by misunderstanding of the semantics of the keywords cancel unnecessary restrictions, provide the user with a rich palette of expressive means and ultimately provide greater comprehensibility of algorithms and programs.
5. Visualization of the cycle – a very useful tool as complicated nested loops with many outlets are often the source of errors difficult. Many of them arise from the confusion associated with outdated habit to describe the cycles of the words. Today, no one is trying to replace the design and construction drawings, verbal descriptions. According to the author, the text form of the cycles in many cases is as anachronistic as a verbal description of a mechanical drawing, or circuitry.

### Attachments

• RS131 (12.76 KB
27.07.2015
)
• R54 (71.4 KB
27.07.2015
)
• R53 (42.99 KB
27.07.2015
)
• R51-52 (48.07 KB
27.07.2015
)
• R49-50 (22.13 KB
27.07.2015
)
• R48 (28.11 KB
27.07.2015
)
• R47 (33.9 KB
27.07.2015
)
• R46 (32.25 KB
27.07.2015
)
• R45 (31.27 KB
27.07.2015
)
• R43-44 (42.87 KB
27.07.2015
)
• R42 (46.12 KB
27.07.2015
)
• R40-41 (64 KB
27.07.2015
)
• R38-39 (36.07 KB
27.07.2015
)
• R37 (33.4 KB
27.07.2015
)
• R34-36 (21.22 KB
27.07.2015
)