CHAPTER 1: EMPATHY IN THEORY
1.4 Decolonial critiques of Western approaches to empathy
1.4.1 A brief outline on decoloniality
1.12. Decision-making constructs
This is a typical situation when, in a certain place of a program, it is neces-sary to execute those or other operators depending on some conditions. The choice of the operators is performed by means of one of two decision-making constructs, If…Then or SelectCase.
The first decision-making construct, If…Then, is called the conditional operator. Below are several versions of this operator.
The simplest conditional operator follows:
If condition Then statement1 where condition is a logical expression.
The computer calculates the value of condition. If True (False) is the result, we will say that the condition is true (false).
If the condition is true, operator statement1 is executed; if the condition is false, operator statement1 is not executed.
Further, the next operator (following the If…Then construct) is executed, regardless of whether or not statement1 was executed (if statement1 is not the GoTo operator).
Let us consider the following example program:
Sub IT1()
Dim X As Byte
X = 12 'initial value of X If (X > 9 And X < 12) Then X = X + 1
X = X + 2
X = X * 2 'final value of X End Sub
For understanding this program, we advise the reader to do the following:
1) install the breakpoint against the EndSub line;
2) click on arrow ► for the program execution up to the breakpoint;
3) make sure that the calculated value of X is equal to 28 during the stop of the program execution;
4) explain this result;
5) click on arrow ► for terminating the program execution.
A special case of the reviewed If…Then construct is the conditional jump operator with the following syntax:
If condition Then GoTo lbl
According to this construct including GoTo, if the condition is true, the jump is performed to the operator labeled by lbl.
The program below is an example of using the conditional jump operator.
Sub IT2()
Dim X As Integer X = 12
2: If X > 9 And X < 12 Then GoTo LastLine X = X - 2
GoTo 2 LastLine:
End Sub
We advise the reader to make the step-by-step execution of this program and to explain why the value of X changes so, instead of differently.
The quantity of operators, which must be executed when the condition is true, may be greater than one. In this case, the following construct is used:
If condition Then statements End If
where statements is an operator block. This conditional operator is per-formed as follows.
If the condition is true, block statements (below the Then keyword) is executed. If the condition is false, block statements is not executed.
Further, the jump is performed to the operator following the If…Then con-struct, regardless of whether or not block statements was executed (if this block does not include the GoTo operator).
Let us consider the following If…Then construct:
If condition Then statement1 Else statement2
If the condition is true, operator statement1 (behind keyword Then) is executed. If the condition is false, operator statement2 (behind keyword
1.12. Decision-making constructs
Else) is executed. Further, the jump is performed to the operator following the If…Then construct, without dependence of what operator was executed earlier, statement1 or statement2 (if these operators are not GoTo).
The program below is an example of using the last construct.
Sub IT3() statementsN, statements do not include GoTo (for brevity).
Let us consider the following construct, which is similar to the previous If…Then construct, but contains blocks instead of operators:
If condition Then below keyword Else) is executed. Further, the jump is performed to the opera-tor following the EndIf keyword combination, without dependence of what block was executed earlier, statements1 or statements2.
Let block statementsN be executed after checking not one but several conditions. In this case, we use the following If…Then construct:
If condition1 Then
If the first condition is true (that is, logical expression condition1 accepts True), then block statements1 is executed. If this condition is false, the second condition (which is behind keyword ElseIf) is checked. If this condi-tion is true (condicondi-tion2=True), then block statements2 is executed, and so on. If conditionN=True, then block statementsN is executed.
If none of the N conditions is true, then block statements (located below the Else keyword) is executed.
Further, the jump is performed to the operator following the EndIf key-word combination, without dependence of what block was executed earlier, statements1, statements2, ..., statementsN or statements.
An example of using the last construct is in codes Listings 5.7 and 5.8 of Section 5.11.
We reviewed several versions of the conditional operator. In addition, let us consider function
IIf(condition, expression1, expression2) Arguments of this function have the following sense:
condition is a logical expression;
expression1, expression2 are arithmetic or logical expressions (Sections 1.8 and 1.10) or strings, which can be considered as expressions (Section 1.19).
Depending on the value of condition (True or False), the IIf func-tion returns into the program the value of expression1 or expression2, respectively.
The program below is an example of the function usage.
Sub IT4()
Dim intA As Integer, strA As String intA = 6
strA = IIf(intA Mod 2 = 0, "Even", "Odd") End Sub
The second decision-making construct, SelectCase, is called the case operator. The syntax of this construct is as follows:
Select Case expression Case value1
statements1 Case value2
1.12. Decision-making constructs operator is performed as follows.
If expression accepts the value of value1, block statements1 is executed. If expression accepts the value of value2, block statements2 is executed, and so on. If expression is not equal to any of the N values (value1, value2, ..., valueN), then block statements (located below the CaseElse keyword combination) is executed.
Further, the jump is performed to the operator following the case operator, without dependence of what block was executed earlier, statements1, statements2, ..., statementsN or statements.
When the same block must be executed at several values of expression, we have to enumerate these values (through a comma) behind the Case key-word.
As an example, let us consider the following program:
Sub Choice() why the value of x changes so, instead of differently.
1.13. Cycles
To execute repeatedly an operator block, we can use one of three cycle opera-tors, For…Next, While…Wend and Do…Loop.
The For…Next cycle is used when the number of the block’s executions is known in advance, i.e., before the first execution of this block. This construct has the following syntax:
For counter = beginning To ending [Step growth]
statements Next [counter]
where counter is a variable of numerical data type (p. 24), beginning and ending are the boundaries of the counter change, growth is the step of this change; beginning, ending and growth are the cycle parameters.
Let us consider the For…Next cycle at a positive value of growth.
At first, the value of beginning is assigned to the counter variable.
Further, condition counter > ending is checked. If the result is True, the cycle is completed, at that, block statements is not executed even once.
If the result of checking condition counter > ending is equal to False, then block statements is executed for the first time. After that, the jump occurs to the cycle beginning. Further, the counter variable’s value increases by growth, and condition counter > ending is checked again. If the result is equal to False, then block statements is executed for the second time, and so on.
The cycle is completed when the check of condition counter > ending gives True. In this case, the operator following the cycle is executed.
As an example of the cycle usage, let us consider the following program for calculating the factorial of number 6:
Sub Factorial1() Dim I As Byte Dim F As Long F = 1
1.13. Cycles For I = 1 To 6 Step 1 F = F * I
Next I End Sub
According to handbook [3], factorial of natural number n (n! is the designa-tion) is the product of the positive integers from 1 to n: n! 1 2 ... n (1! 1).
We advise the reader to do the following:
1) execute the Factorial1 program step-by-step, watching the F varia-ble’s value;
2) replace 6 (parameter ending) by 13 in the cycle operator;
3) run the resulting Factorial1 program for calculating 13!;
4) explain the reason of the stop with information Run-time error ‘6’: Over-flow, using the description of the Long data type in Appendix 1.
At a negative value of the growth parameter, the For…Next cycle works as at a positive value, but:
condition counter < ending is being checked;
the counter variable cannot be of the Byte data type.
The following 2nd version of the program for calculating 6! is an example of using a negative value of the growth parameter.
Sub Factorial2()
If the Step keyword is omitted, the step of the counter change is equal to unity by default.
Arithmetic expressions may be used as the cycle parameters (beginning, ending and growth). It is important that all variables in these arithmetic expressions had numerical values before the For…Next cycle work.
As an example of such usage of arithmetic expressions, let us consider the following 3rd version of the program for calculating 6!:
Sub Factorial3()
Const e As Double = 2.718281828 Dim J As Byte
Dim N As Byte
In this program, arithmetic expression N^2-3 is used as parameter ending.
The N variable is equal to 3, and N^2-3 is equal to 6.
The absence of the Step keyword says that the step of the J variable change is equal to 1, and J changes from 1 to 6.
Frequently it is required to leave the cycle before completion of its execution.
In this case, the For…Next cycle has the following syntax:
For counter = beginning To ending [Step growth]
[statements1]
If condition Then Exit For [statements2]
Next [counter]
The ExitFor operator is used for immediate exit from the cycle. It is a part of the simplest conditional operator. The last cycle works as follows.
For each value of the counter variable, after executing the statements1 block, the computer calculates the value of logical expression condition.
If this value is False, the cycle continues to work. Otherwise, the jump is per-formed to the operator following the cycle construct (without executing block statements2).
As an example of using the ExitFor operator, let us consider the following 4th version of the program for calculating 6!:
Sub Factorial4()
1.13. Cycles
The While…Wend cycle is used when the number of the block’s executions is not known in advance. The syntax of this cycle follows:
While condition statements Wend
The While…Wend cycle work begins with calculating the value of logical expression condition. If condition=False, the cycle is completed, i.e., the jump is performed to the operator following the Wend keyword.
If condition=True, block statements is executed. After that, the value of logical expression condition is calculated again, and so on.
The 5th version of the program for calculating 6! follows:
Sub Factorial5() Dim I As Byte Dim F As Long F = 1
I = 1
While I <= 6 F = F * I I = I + 1 Wend
End Sub
The Do…Loop cycle, as well as the While…Wend cycle, is used when the number of the block’s executions is not known in advance. Four versions of this construct exist.
The first version is the DoWhile…Loop cycle with the following syntax:
Do While condition statements Loop
The DoWhile…Loop cycle work begins with calculating the value of logi-cal expression condition. If condition=False, the cycle is completed, i.e., the jump is performed to the operator following the Loop keyword. If condition=True, block statements is executed. After that, the value of logical expression condition is calculated again, and so on.
The DoWhile…Loop cycle is equivalent to the While…Wend cycle reviewed above.
The 6th version of the program for calculating 6! follows:
Sub Factorial6() Dim I As Byte Dim F As Long F = 1
I = 1
Do While I <= 6 F = F * I I = I + 1 Loop
End Sub
One more example of using the DoWhile…Loop cycle is the following program for the movement along the x axis:
Sub Steps1()
Dim x As Single Dim h As Single
h = 0.5 'step equals 0.5
x = 44 'initial value of x equals 44 Do While x < 55 'final value of x equals 55 x = x + h 'value of x increases by h Loop
End Sub
We advise the reader to make the step-by-step execution of the Steps1 program, watching the x variable change.
The DoUntil…Loop cycle, which is the second version of the Do…Loop construct, has the following syntax:
Do Until condition statements Loop
The DoUntil…Loop cycle work begins with calculating the value of logi-cal expression condition. If condition=True, the cycle is completed, i.e., the jump is performed to the operator following the Loop keyword.
If condition=False, block statements is executed. After that, the value of logical expression condition is calculated again, and so on.
1.13. Cycles
The program with the DoUntil…Loop cycle for the movement along the x axis has the following form:
Sub Steps2()
Dim x As Single Dim h As Single
h = 0.5 'step equals 0.5
x = 44 'initial value of x equals 44 Do Until x >= 55 'final value of x equals 55 x = x + h 'value of x increases by h Loop
End Sub
There is a situation when, during the work of the DoWhile…Loop and DoUntil…Loop cycles, block statements is not executed even once because the condition of completing the cycle is checked before the block execu-tion. Sometimes it is inconvenient.
The Do…LoopWhile cycle, which is the third version of the Do…Loop construct, has the following syntax:
Do
statements
Loop While condition
The Do…LoopWhile cycle work begins with executing operator block statements. After that, the value of logical expression condition is calculated. If condition=False, the cycle is completed. Otherwise, block statements is executed again, and so on.
The program with the Do…LoopWhile cycle for the movement along the x axis has the following form:
Sub Steps3()
Dim x As Single Dim h As Single
h = 0.5 'step equals 0.5
x = 44 'initial value of x equals 44 Do
x = x + h 'value of x increases by h Loop While x < 55 'final value of x equals 55 End Sub
The Do…LoopUntil cycle, which is the fourth version of the Do…Loop construct, has the following syntax:
Do
statements
Loop Until condition
The Do…LoopUntil cycle work begins with executing operator block statements. After that, the value of logical expression condition is calculated. If condition=True, the cycle is completed. Otherwise, block statements is executed again, and so on.
The program with the Do…LoopUntil cycle for the movement along the x axis has the following form:
Sub Steps4()
Dim x As Single Dim h As Single
h = 0.5 'step equals 0.5
x = 44 'initial value of x equals 44 Do
x = x + h 'value of x increases by h Loop Until x >= 55 'final value of x equals 55 End Sub
During the work of the Do…LoopWhile and Do…LoopUntil cycles, block statements is executed at least once because the condition of complet-ing the cycle is checked after the block execution.
All four versions of the Do…Loop cycle can contain the ExitDo operator intended for immediate exit from the cycle. In the usage, this operator is similar to the ExitFor operator of the For…Next cycle.
For the While…Wend cycle, there is no operator similar to the ExitFor and ExitDo operators.
1.14. Manifestation of the error of real numbers’ computer representation