Menu
Is free
registration
home  /  Education/ Loops and other controls. Structured programming

Loops and other controls. Structured programming

Branching operator

The branch operator (conditional branch) allows you to execute certain program instructions depending on logical conditions. In Visual Basic, the branch operator can be used in two forms: inline and block.

online exchange of student papers ">

Example 1

For example, If a> b Then max = a Else max = b.

If you need to execute multiple statements, they are separated by colons.

Example 2

For example, If a> 0 Then b = a + 1: c = a \ 2.

The block syntax is more powerful, more structured, and more readable.

Block syntax:

Condition is a boolean expression that can take on a value True(true), False(false) or Null which equates to False... When a block branching statement is executed, the condition is checked and, if it is true, the statement following Then... If the condition is not true, it is checked condition2 following ElseIf... When a true value is found, operator_of_true2 is executed, which follows Then, after which the program goes beyond EndIf(i.e. subsequent ElseIf, if any, are not checked). If the true conditions for ElseIf not found, operator on false_condition is executed.

Figure 3. An example of block syntax. Author24 - online exchange of student papers

Selection operator

Case selection operator executes certain operators depending on the set of values ​​of the tested expression or variable. Select operator syntax:

Figure 4. The syntax of the selection statement. Author24 - online exchange of student papers

Value is a variable or expression that is tested against one or more conditions. The list of values ​​is specified with a comma, the range of values ​​is specified using a service word To(e.g. 5 To 9).

Example 3

By the number of the month in the year, display a message about what time of year the specified month belongs to.

Structured operators - these are constructions built according to certain rules from other operators. Structured operators include:

Compound operator

Conditional operator

Selection Operators

Loop Operators

With statement

1.Compound Operator

Composite operator is a group of any number of any operators, separated from each other by a semicolon, and delimited by the operator brackets begin and end.

Compound operator format:

begin<Оператор1>; ... ; <ОператорN>;

Regardless of the number of operators included in it, the compound operator is perceived as a whole. The most commonly used compound operator is in conditional and loop statements.

Compound operators can be nested within each other, with no restrictions imposed on the nesting depth of compound operators.

2.Conditional Operator

Conditional operator enforces or does not comply with certain statements depending on the fulfillment of certain conditions.

Conditional statement format:

If then<Оператор1> ;

The condition is a boolean expression. The operator works as follows: if the condition is true (has the value True), then operator1 is executed, otherwise operator2 is executed. Both operators can be compound.

A conditional statement can be written in abbreviated form when the word else and statement2 after it are absent.

To organize forks into three directions or more, you can use several conditional statements, nested within each other. Moreover, each else corresponds to the then immediately preceding it. Due to possible errors, you should avoid large nesting of conditional statements in each other.

3.Operator selection

Operator of choice is a generalization of the conditional operator and allows you to choose from an arbitrary number of available options. This statement consists of an expression called selector, a list of choices and an optional else branch, which has the same meaning as in a conditional statement.

Select operator format:

case<Выражение-селектор>of

<Список1> : <Оператор1>;

<СписокN> : <ОператорN>

Selector expression must be of ordinal type. Each variant is a list of constants, separated by a colon from the corresponding operator. The list of selection constants consists of an arbitrary number of values ​​and ranges, separated by commas. The range boundaries are written in two constants separated by the ".." separator. The type of constants must match the type of the selector expression.

The selection statement is executed as follows:

1. The value of the selector expression is evaluated.

2. The options are sequentially scanned to see if the selector value matches the constants and values ​​from the ranges of the corresponding list.

3. If this search is successful for the next variant, then the operator of this variant is executed. After that, the execution of the selection statement ends.

4. If all checks were unsuccessful, then the operator after the word else is executed (if any).

Example. Selection operator

caseNumberDay of

1..5: strDay: = "Working day";

6..7: strDay: = "Day off"

else strDay: = "";

Depending on the value of the integer variable NumberDay containing the number of the day of the week, the string variable strDay is assigned the corresponding value.

Chapter 6. CONTROL STRUCTURES Assignment Operator Simple and Composite Operators Conditional Operator Multiple Choice Operator Preconditioned Loop Operator Postconditioned Loop Operator Parameterized Loop Operator and Unconditional Jump Procedures


2 Ch. 6. CONTROL STRUCTURES Assignment operator An operator is a programming language construct used to specify an action or a sequence of actions in a program on data. The set of program operators implements the algorithm inherent in it. Any operator implies some action. The process of "pushing" a value into a variable is called assignment (the first assignment is called initialization). Assignment is carried out using a special construction - the assignment operator: variable identifier: =: = expression Var W, H: Integer; Begin W: = 23; H: = 17; W: = W * H; End.


3 Ch. 6. CONTROL STRUCTURES Simple and compound statements Two consecutive statements must be separated by a semicolon (meaning the end of a statement): a: = 11; b: = a * a; Write (a, b); A compound statement is a sequence of statements treated as a single statement. It is formatted using the reserved words begin and end (operator brackets). An operator in a program is a single, indivisible statement that performs an action. A simple operator does not contain any other operators (assignment operator, procedure call, ...). begin a: = 11; b: = a * a; Write (a, b) end;


5 then begin X: = X + 5; Y: = 1 end else Y: = -1; The conditional operator is used for programming branches, i.e. situations when it becomes necessary under certain conditions to execute "title =" (! LANG: 4 Ch. 6. CONTROL STRUCTURES Conditional statement if K> 5 then begin X: = X + 5; Y: = 1 end else Y: = -1 ; The conditional operator is used for programming branches, i.e. situations when it becomes necessary, under certain conditions, to execute" class="link_thumb"> 4 !} 4 Ch. 6. CONTROL STRUCTURES Conditional statement if K> 5 then begin X: = X + 5; Y: = 1 end else Y: = -1; The conditional operator is used for programming branches, i.e. situations when it becomes necessary under certain conditions to perform various actions. The conditional operator has the structure: if boolean expression then operator else operator Only one operator can be written in each branch. 5 then begin X: = X + 5; Y: = 1 end else Y: = -1; The conditional operator is used for programming branches, i.e. situations when it becomes necessary under certain conditions to execute "> 5 then begin X: = X + 5; Y: = 1 end else Y: = -1; The conditional operator is used to program branches, i.e. situations when it becomes necessary when certain conditions to perform various actions. The conditional operator has the structure: if logical expression then operator else operator Only one operator can be written in each branch. "> 5 then begin X: = X + 5; Y: = 1 end else Y: = -1; The conditional operator is used for programming branches, i.e. situations when it becomes necessary under certain conditions to execute "title =" (! LANG: 4 Ch. 6. CONTROL STRUCTURES Conditional statement if K> 5 then begin X: = X + 5; Y: = 1 end else Y: = -1 ; The conditional operator is used to program branches, i.e. situations when it becomes necessary, under certain conditions, to execute"> title="4 Ch. 6. CONTROL STRUCTURES Conditional statement if K> 5 then begin X: = X + 5; Y: = 1 end else Y: = -1; The conditional operator is used for programming branches, i.e. situations when it becomes necessary, under certain conditions, to perform"> !}




6 Ch. 6. CONTROL STRUCTURES Multiple choice operator The choice operator is used to implement several alternative options for actions, each of which corresponds to its own values ​​of some parameter. case expression of constant / range else statements: end statement; The value and also must be of one of the ordinal types (except LongInt). Depending on the value, the operator is selected, which is preceded by a selection constant equal to the calculated value (the alternative is the operators after the else). Constant values ​​must be unique in each set, i.e. they can only appear in one form.


7 Ch. 6. CONTROL STRUCTURES case I of (I: Word) 1: X: = X +1; 2.3: X: = X +2; 4..9: begin Write (X); X: = X + 3 (mb ";") end (mb ";") else X: = X * X; Writeln (X) (maybe ";") end;


8 Ch. 6. CONTROL STRUCTURES "While" loop operator (with precondition) while conditional expression do operator (loop body) after the do function word will be executed cyclically as long as the logical condition is fulfilled, ie. while the value is True. For a loop to have a chance to ever terminate, the contents of its body must affect the loop condition. The condition must consist of valid expressions and values ​​defined before the first execution of the loop body. VarF, N: LongInt; (computation 10 Begin F:= 1; N:= 1; while N !}


9 Ch. 6. CONTROL STRUCTURES "Before" loop statement (with postcondition) The statements between the words repeat and until form the body of the loop. If True, the loop ends. Loop "While" - "while the condition is true, execute the operators of the body." Loop "Before" - "execute the body of the loop until the condition becomes true"; repeat until False; repea t operator until conditional expression;


10 Ch. 6. CONTROL STRUCTURES A loop operator with a parameter (loop over a counter) is a variable of ordinal type, the values ​​and must be of the same type. The value changes in ascending (when using the reserved word to) or descending (downto) order from value to value with a constant step equal to the interval between the two nearest values ​​in the type to which it belongs (for integer types, this is 1, for character types, from one character to another when increasing the code by 1, etc.). For loops can be nested if none of the nested loops uses or modifies variables - parameters of the outer loops. Used to organize "strict" cycles that must be done a specified number of times. fo r loop parameter: = expression 1 to expression 2 do downto statement


12 Ch. 6. CONTROL STRUCTURES Unconditional branch operator A label can appear anywhere in the program between operators and is separated from the second operator by a colon ":". The scope of unconditional jump operators is strictly localized. Jumps on the goto operator between procedures, as well as between the main block and a procedure, are prohibited. The unconditional jump operator transfers execution control to the program location indicated with the help of the label (it is "superfluous" from the point of view of the theory of structured programming). goto label Label unsigned integer; label identifier, Syntax diagrams and: LabelL1, L2; Begin ... goto L1; ... L1: goto L2; ... L2: End.


13 Ch. 6. CONTROL STRUCTURES Unconditional jump procedures Non-structural control transfer procedures when working with cyclic structures: Break - implements an exit from a loop of any type; Continue - moves to the next iteration of the loop, ignoring the statements remaining to the end of the loop body. Exit and Halt procedures are specially designed to exit program blocks (procedures, functions, main program block). Halt () exits the program by returning the specified exit code to the operating system. Exit exits the subroutine unconditionally. If the procedure is used in the main block, then it is performed in the same way as Halt.

Loop statements Loop statements are used to organize repetitive calculations. To organize a loop, a variable called a loop parameter or a loop control variable is needed. Any cycle consists of: initial settings or block of initialization of the cycle parameter; the body of the loop, that is, those statements that are executed several times; cycle parameter modification block; checking the exit condition from the loop, which can be placed either before the body of the loop, then we talk about a loop with a precondition or after the body ...


Share your work on social media

If this work did not suit you at the bottom of the page there is a list of similar works. You can also use the search button


Topic 2 Control operators

2.1 Basic constructs of structured programming

V programming theoryit has been proved that a program for solving a problem of any complexity can be composed only of three structures, called following, branching and looping. They are called basic designsstructured programming.

Following is a construction that is a sequential execution of two or more operators (simple or compound).

Branching specifies the execution of either one or the other operator, depending on the fulfillment of a condition.

Cycle specifies multiple execution of the statement.

A feature of the basic structures is that any of them has only one input and one output, so the structures can be nested into each other in an arbitrary way.

Figure 2.1 - Basic constructions of structured programming

The purpose of using basic constructs is to get a program with a simple structure. Such a program is easy to read, debug, and, if necessary, make changes to it.

Any expression that ends with a semicolon is treated as a statement whose execution consists of evaluating the expression.

2.2 Relational and logical operations

Relationship operations(<, <=, >,> =, ==,! =) compare the first operand with the second. Operands can be of arithmetic type or pointers. The result of the operation is the value true or false ... Equality and inequality comparisons have lower precedence than other comparison operations. For example: x> = 0, y! = 10, z == 0.

ATTENTION! Note the difference between the equality test (== ), the result of which is true or false , and the assignment operation (= ), which results in the value assigned to the left operand.

Logical operations(&&, ||, ^). Operands logical operations AND (&&), OR (|| ), EXCLUSIVE OR (^ ) must be of a type that can be converted to a type bool, with the operands in one operation can be of different types. The result of the operation is true or false.

The result of the operation boolean AND is true only if both operands are valid true ... Operation Result logical OR is true if at least one of the operands is true ... Operation Resultlogical EXCLUSIVE OR is true if one of the operands is true and the second is false. Logical negation ( !) results in the value false if the operand is true, and true if the operand is false. Operand can be of arithmetic type. In this case,implicit conversion to type bool ... Logical operations are performed from left to right. If the value of the first operand is sufficient to determine the result of the operation, the second the operand is not evaluated.

Table of results of operations AND, OR, EXCLUSIVE OR, NOT

(A and B are operands)

A && B

A || B

A ^ B

Examples of expressions with logical operations:

x> 0 && y<=10

(a< -1 && b >0) || c! = 100

Conditional operation(? :). This is the only one in C ++ ternary operation (has three operands), its format is:

operand_1? operand_2: operand_3

Operands are calculated from left to right. The result of evaluating the first operand must be of a type that can be converted to a type bool ... If the result is true , then the result of the execution of the entire conditional operation will be the value of the second operand, otherwise, the value of the third operand. Their types can be different.

Example: suppose that some integer value is required to increase by 1 if its value does not exceed n , otherwise it took the value 1. This can be written with a single line of code:

i = (i< n) ? i + 1: 1;


2.3 Branching operators. Conditional if statement

Conditional if statementis used to branch the computation process into two directions. Algorithm diagram operator is shown in Figure 2.1. Operator format:

if (expression) operator_1; [else statement_2;]

First, an expression is evaluated, which can be of an arithmetic or pointer type. If it is not equal to zero, i.e. equals true , then the first statement is executed, otherwise the second. After that, control is transferred to the operator following the conditional one. One of the branches may be missing.

If more than one statement needs to be executed on a branch, they must be enclosed in a block. A block can contain any statements, including descriptions and other conditional statements.

Examples:

if (a< 0) b = 1;

if (a< b && (a >d || a == 0))

B ++;

else

(b * = a; a = 0;)

if (a< b)

if (a< c )

M = a;

else

M = c;

else

If (b< c )

M = b;

else

m = c;

Example 1 branch missing else ... Such a construction is called "operator skip" because assignment is either executed or skipped depending on whether the condition is met.

If you want to check several conditions, they are combined by signslogical operations... For example, the expression in example 2 will be true if the condition a< b и одно из условий в скобках. Если опустить внутренние скобки, будет выполнено сначала логическое И, а потом – ИЛИ.

Operator in example 3 calculates the smallest value of three variables.

By operator syntax if there should be no more than one operator in its branches. If there are more of them, then they must be combined into a block using curly braces or with comma operations (,).

Example. A shot is fired at the target shown in Figure 3.2. Determine the number of points.

Figure 3.2 - Target

#include

int main ()

float x, y;

int kol;

Printf ("\ n Enter the coordinates of the shot ");

Scanf ("% f", & x);

Scanf ("% f", & y);

If (x * x + y * y< 1)

Kol = 2;

Else

If (x * x + y * y< 4)

kol = 1;

else

kol = 0;

printf ("\ n Points:% d", kol);

2.4 Branching operators. Multiple choice operator switch

Switch statementis intended for branching the computation process into several directions. Operator format:

switch (expression)

Case constant_expression_1: operators 1;

Case constant_expression_2: statements 2;

...

Case constant_expression_n: statements n;

The statement execution starts withevaluating an expression(it must be integer ), and then control is transferred case -label - to operators marked with a constant expression, the value of which coincides with the calculated one, after which all other branches are sequentially executed, if the exit from no switch is explicitly specified.

All constant expressions must have different meanings, but be the sameinteger type... Several labels can follow in a row. If there is no match, the statements after the word are executed default (and in its absence, control is transferred to the next switch statement).

If in any of case -labels missing operator break , then the operators in the next case -label and so on until the operator is found somewhere break.

Example (the program implements the simplest calculator for 4 actions):

#include

int main ()

int a, b, res;

char op;

printf ("\ n Enter 1st operand: ");

scanf ("% d", & a);

printf ("\ n Enter the operation sign: ");

scanf ("% c", & op);

printf ("\ n Enter the 2nd operand: ");

scanf ("% d", & b);

bool f = true;

Switch (op)

Case "+": res = a + b; break;

Case "-": res = a - b; break;

Case "*": res = a * b; break;

Case "/": res = a / b; break;

default: printf ("\ n Unknown operation"); f = false;

if (f)

printf ("\ n Result:% d", res);

Exit the switch usually done with operators break or return.

2.5 Loop statements

Loop Operators are used to organize repetitive calculations.

To organize the loop, you need a variable called loop parameter or loop control variable... Any cycle consists of:

  • initial settings or loop parameter initialization block;
  • loop bodies , that is, those statements that are executed several times;
  • cycle parameter modification block;
  • check the exit condition from a loop that can be placed either before loop bodies (then they talk about the cycle with a precondition), or after the body of the loop (a loop with a postcondition).

Figure 3.3 - Two types of cycles

One pass of the loop is called iteration ... Integer loop parameters, changing by an integer on each iterations are called cycle counters.

You cannot transfer control from the outside to the inside of the loop. Exit from the loop is possible both when the exit condition is met, and by operators break, return or unconditional jump goto.

2.6 Loop with precondition (while)

Loop with precondition implements the algorithm scheme

while (expression) operator;

For example:

The expression defines the repetition condition loop bodies represented by a simple or compound operator. If the expression is not 0 (true), the loop statement is executed, and then the expression is evaluated again. If the expression is 0 (false) on the first check, the loop will not be executed even once. The expression type must be arithmetic or convertible.

function values y = x 2 +1 in the entered range):

#include

int main ()

float Xn, Xk, Dx;

float X = Xn; // initial settings of the cycle

While (X<= Xk) //проверка условия выхода

Printf ("\ n% 5.2f% 5.2f", X, X * X + 1); // body

X + = Dx; //modification

2.7 Loop with postcondition (do while)

Loop with postcondition implements the algorithm scheme given below and looks like:

do statement while expression;

A simple orcompound operatorthat composes the body of the loop, and then the expression is evaluated. If it is not equal to 0 (true), the body of the loop is executed again, and so on, until the expression becomes equal to zero (false) or sometransfer operator... The expression type must be arithmetic or convertible.

Example (the program checks the input):

#include

int main ()

char answer;

printf ("\ n Buy an elephant!");

scanf ("% c", & answer);

while (answer! = "y");

2.8 The for loop

For loop implements the algorithm scheme given below and has the form:

for (initialization block; condition check block; modification block)

Loop body;

Example:

Initialization blockused to declare and initialize the values ​​used in the loop. In this part, you can write multiple operators, separated by commas.

Condition check blockdefines the condition of the loop execution: if it is not equal to 0 (true), the loop is executed.

Modification blockperformed after each iterations cycle and usually serves to change the parameters of the cycle. In the part of modifications, you can write several operators separated by commas.

Simple or compound operator represents loop body ... Any part of the operator for can be omitted (but leave semicolons in place!). In any part, you can use the "comma" operation (sequential calculation), for example:

for (int i = 1, s = 0; i<= 100; i++)

S + = i; // sum of numbers from 1 to 100

Example (the program prints the tablefunction values y = x 2 +1 in the entered range):

#include

int main ()

float Xn, Xk, Dx;

printf ("Enter the range and step for changing the argument:");

scanf ("% f% f% f", & Xn, & Xk, & Dx);

For (float X = Xn; X<= Xk; X += Dx)

Printf ("\ n% 5.2f% 5.2f", X, X * X + 1);

2.9 Nested loops

Each of the loop operators can be nested in any other in any order. The nesting depth of the loops is not limited. It is determined only by the algorithm of the problem being solved.

Below is an example of nested loops for

This program snippet works as follows. For one value of the outer loop parameter i (for example, i = 1 ) parameter of the inner loop j changes in the range from minimum to maximum value (from 1 to M ). Only then the parameter i increases by one. Thus, the body of the loop will be executed N * M times.

Other variants of nested loops work in a similar way: the parameter of the outer loop changes slowly, and the inner one changes quickly. It is recommended to master them yourself. To do this, the inner loop algorithm diagram must be inserted in its entirety instead of the loop body block.

2.10 Control Transfer Operators

In C ++ there are five operators that change the natural order of computation:

  • the loop exit statement, and break switch;
  • jump operator to the next loop iteration continue;
  • function return statement return;
  • operator unconditional jump goto;
  • throw operator throw.

Break statement used for immediate termination loop or switch statement ... Execution is transferred to the next statement after the completed one.

Let's consider its use with an example.open iterative loop for ... For example, calculating the sum of numbers from 1 to 100.

int i = 1, sum = 0;

for (;;)

If (i> 100) break;

sum + = i;

i ++;

Go to next iteration operator loop continue skips all statements remaining to the end loop bodies , and transfers control to modify the parameters of the cycle (in the case of a cycle for ) and the beginning of the next iterations.

Let us consider its use by the example of calculating the sum 1 / x if x varies in the range [-5, 5].

#include

int main ()

float X, Sum = 0;

for (X = -5; X<= 5; X++)

If (X == 0)

Continue;

Sum = Sum + 1 / X;

Printf ("\ n Sum =% f", Sum);

Function return operator return ends the function and transfers control to the point where it was called. We'll cover it along with the features in the related topic.

Unconditional Jump Operator goto has the format:

goto label;

The body of the same function must contain exactly one construction of the form:

label: operator;

Goto statement transfers control to the marked operator. Label Is a regular identifier,scopewhich is the function in the body of which it occurs.

Usage unconditional jump operatorjustified in two cases:

  • forced exit down the text of the program from severalnested loopsor switches;
  • transition from several places in a function to one (for example, if you always need to perform some actions before exiting a function).

In other cases, there are more suitable means for recording any algorithm.

An exceptional situation(or just an exception ) is generated either by the programmer using the operator throw or the runtime itself. This happens when any errors occur during program execution, such as division by zero or overflow. Mechanism exception handlingimplemented in C ++ , allows you to react to such errors and thus avoid the abnormal termination of the program. It will be covered in another topic.

Other similar works that may interest you. Wshm>

2784. Condition and selection operators 16 KB
If condition operator. Therefore, you can already write the following assignment statements: Koren: = Sqrtxy; Modul: = bsxy. To implement such conditional jumps in the Pascal language, the If and Else statements, as well as the unconditional jump operator Goto, are used. Consider the If statement.
2750. Write and WriteLn Statements 12.34 KB
Write eng. The WriteLn operator performs the same action, but since it also has the Ln line ending in English. General view: Write list of expressions WriteLn list of expressions The Write and WriteLn procedures are used not only to display the result, but also to display various messages or requests.
6706. Structured Query Language - SQL: History, Standards, Basic Language Operators 12.1 KB
The structured query language SQL is based on the relational calculus with variable tuples. The SQL language is designed to perform operations on tables, creation, deletion, change of structure, and on data of tables, selection, change, addition and deletion, as well as some related operations. SQL is a non-procedural language and does not contain statements to control the organization of input / output routines, etc.

The simplest structure is following. It can be represented like this:

Modules "a" and "b" can contain either one operator or any number of structures following one after another, incl. and discussed below.

The fork structure (if - then - otherwise) serves to choose one of two possible ways of executing the algorithm. It is based on verification. The fork looks like this:

IF-THEN-ELSE structures can be nested in each other, for example, in this way.

The number of nested structures is limited by the capabilities of the PC and the software installed on it. This amount is usually specified in the language description. To ensure readability, the nested structures can be replaced with rectangles, and the block diagram of each rectangle can be shown in detail on a separate sheet. In general, any block diagram or program is better readable if it is placed entirely on one page.

The structure shown in the last block diagram allows you to choose one of three paths. Similarly, using nested structures, you can organize the selection of one of any number of paths. Since the need for this appears quite often, a special structure has been introduced - a choice, which looks like this

Here, the symbol "P" still denotes the condition, based on the fulfillment of which one of the possible paths is selected.

When developing algorithms, it is often extremely important to repeat an operation or group of operations. To display such fragments of the algorithm, special structures are provided - cycles. Οʜᴎ There are three types: cycle-bye, cycle-before and cycle with a counter. The work of the cycle is depicted by the following flowchart.

Before the first execution of the block of statements, which is usually called the body of the loop, the condition "P" is checked and, if it is true, the body of the loop is executed, and control returns to the beginning of the loop. Then the condition is checked again, and so on until the loop condition becomes false. In this case, the execution of the cycle is terminated. It is executed as long as the condition is met.

Cycle-do is organized differently.

The verification of the truth of the loop condition is performed after the execution of the loop body, and the exit from it is carried out when the condition is true. Τᴀᴋᴎᴍ ᴏϬᴩᴀᴈᴏᴍ, the body of the loop is always executed once, unlike cycle-bye, which is not executed even once if the loop condition is not met.

The third type of cycle is a counter cycle. It is used in cases where it is extremely important to repeat the body of the loop a certain number of times. Its structure can be depicted by the following block diagram.

It shows that this cycle is a special case cycle-bye, but since this case is often encountered, in programming languages, in particular, in VBA, a special operator is introduced to describe a loop with a counter.
Posted on ref.rf
For this reason, we have allocated a special structure for this cycle.

As an example, consider a block diagram of finding the maximum element in a table of N numbers.

Here Max is the maximum number, i is the number of the number in the table of numbers X, N is the size of the table. The block diagram contains the following structural constructs: follow, loop-bye, which is executed as long as the number of the checked number is less than or equal to the size of the table, and a fork, in which a path is selected containing the assignment of the current number from the table to the variable Max, in that case if this variable is less than the current number.

The main governing structures are concepts and types. Classification and features of the category "Main control structures" 2017, 2018.