Contents 0 Introduction 4Editing Component and Structures
Table 3. How code relates to the flowchart. For more information on constructing the logical conditions needed by the If structure, see section 3.9.5.
T Figure 15. The If Else Structure he If_Else structure differs from the standard If structure, as it has two possible paths of execution. As well as having a slightly different visual appearance, components can be placed on both the true or false paths of this structure, as shown in figure 15.b Like the other control structures of Progranimate, the If_Else takes a Boolean expression during its definition. At run time, the flow of execution is determined by evaluating the expression it contains. If the result is true, control is passed down the true left side path of the If structure. If the result is false, control is passed down the left side of the If_Else’s structure. In code, the IF and the Else parts of the structure represent the true and false paths of the flowchart. As the Boolean expression is evaluated, it will highlight either the left or right edges of the If _Else structure’s diamond to indicate the direction in which the flow of control will move. Table 4 below demonstrates this. The blue and red lines and arrows demonstrate how the flowchart relates to the generated code.
Table 4. How the code relates to the flowchart. For information on constructing the logical conditions needed by the If structure, see section 3.9.5. *NOTE*:Synchronised Highlighting With the IF_Else Structure. The IF_Else structure has some minor enhancements to its visual components that make it easier to relate its flowchart representation to its code representation. Clicking on the left side of the If structure’s diamond in the flowchart view will cause the code associated with its If to highlight. Clicking on the right side of the If’s diamond will cause the code relative to the structure’s Else to highlight. When the left side of the End_If is clicked in the flowchart, the relevant closing bracket or End_If statement will be highlighted in the code view. When the right side of the End_If is clicked the relevant closing curly bracket or End Else statement will be highlighted in the code view. The same is true in reverse; clicking a line of code relating to the If_Else structure will cause the relevant side of the relevant component in the flowchart view to highlight.
The While control structure allows for looping within programs. Its role is to continually re-direct the flow of control though a set of components or sub structures, until the expression it contains evaluates to false. Figure 16 shows the flowchart representation of a While loop with and without internal components. Like the If and If_Else structures, the While structure is associated with a Boolean expression during its definition. During animation, when the While is reached, its expression is evaluated. If its expression evaluates to true, then the flow of execution is directed downwards within the While’s structure. The components and sub structures inside the While loop are then executed in order until the End_While is reached. The f Figure 16. The While Looping Structure low of execution is then redirected to the top of the loop, where its expression is re-evaluated and the flow is directed appropriately. Looping continues until the expression evaluates to false. If and when the expression evaluates to false, the flow of execution is directed down the exit path, past the While loop, and on to the next component or structure below. To add the first component within a While’s structure the user must click on its decisional diamond in the flowchart, or on the While line of text in the code. This will add a component inside its structure in-between the While and End_While in both the flowchart and code. Other components or structures can then be added inside a While’s structure by interacting with the code and flowchart in the standard way. Components cannot be added to the loop return or exit paths of a While loop. Doing so causes a placement error to be generated and displayed. Table 5 demonstrates the relationship between the visual flowchart structure and the code generated for a While structure. For information on constructing the logical conditions needed by the While structure, see section 3.9.5
Table 5. How the code relates to the flowchart
The For loop provides an additional looping structure. The for loop behaves like a while loop except it increments a variable without the need for an additional assignment statement. Depending on the language chosen the format and semantics of the For loop differs. Visual Basic For Loop Visual Basic (.Net and 6.0) utilizes a traditional style for loop with start , end and step values as follows. For controlVariable = start TO end STEP stepValue ‘Code to be looped goes here. Next ‘(the end of the loop) The control variable can be a integer or double type variable or array element. Its value will change with each loop. When the loop begins the control variable is assigned a starting value: controlVariable = start The loop will terminate when the controlVariable equals the end value. With each loop the value of the control variable is incremented by the amount specified by the step value. If no step value is specified this value is assumed to be one. Table 6 demonstrates the relationship between the visual flowchart structure and the code generated for a While structure The code shown below will loop 100 times during which the value of variable i will be printed. This will result in the values 1 to 100 being printed.
Table6. The For Loop in VB Using the Step Value If you modify the above to add a step the control variable will increment by a different amount with each loop. In the example below we supply a step value of 2. The program should loop 50 times printing 1,3,5,7,9 and so on until the control variable exceeds 100. For i = 0 TO 100 STEP 2 Console.WriteLine(i) Next
It is also possible to loop backwards in this case the start value needs to be higher than the end value and the step needs to be negative for example: For I = 100 TO 1 STEP -1 Console.WriteLine(i) Next
It is also possible to loop in decimal increments providing the control variable and step value are of the double data type. For this example imagine the variable d is a double. For d = 1.0 to 5.5 STEP 0.1 Console.WriteLine(d) Next
The for loops can handle the same level of complexity that VB allows. For example all of the following examples are value. Example A. For x = y+2 TO z -2 Next Example B For values[1] = anArray[0] TO anotherArray[x] STEP otherArray[0] Next Example C. For values[i] = 1+ x TO y 2 STEP z/2 + (2 * z ) Next The Definition Panel a Visual Basic For Loop The definition panel For a Visual Basic for loop is the most complex of all the definition panels. However, it is still very simple and intuitive to use. Figure 17 The Visual Basic For Loop Definition Panel All fields of this panel are mandatory except step which is optional. When no specified the step will not show in the code but will cause a default increment of 1. The control variable must be an integer or decimal variable or array element. In all other fields literal values, variables and expressions may be entered as long as they result in an integer or a double data type. Any user errors will appear below the relevant field where the error has been detected. Java Style For Loops In the Java language the format of the For loop is significantly different than with Visual Basic. The for loop in this language relates more closely to a while loop where it relies in the use of a Boolean condition. Like the for loop it also manages the initialization and incrementation of a control variable. In Java the for loop takes the following form: for ( initialization; boolean expression; increment ) { //Code goes here } The initialisation section is used to initialize the control variable with an initial value as the loop begins. The Boolean expression is evaluated with each loop and while true looping continues. When false looping stops and the flow of execution is diverted past the for loop and onto the next instruction. It is common practice to have a Boolean expression which tests the value of variable initialized in the initialization section, though any valid Boolean expression may go here. With each loop the value of the expression contained in the increment is evaluated. It is common practice to include in here an expression to increment the a control variable specified in the initialization and Boolean expression of this component. However any valid assignment expression may go here.
Table7. The For Loop in Java The expressions contained within the Java for loop may include anything that is permitted by the Java language. Some examples are shown below. Basic Looping Printing numbers 1 to 100 in increments of two For ( i = 0 ; i <= 100; i= i + 2) { System.out.println (i); } Negative Increments (Looping Backwards) Printing number from 100 down to 1. For ( i = 10; i > 0; i= i – 1) { System.out.println(i); } Decimal Increments Outputting 55 numbers between 1.0 to 5.5. in increments of 0.1 For ( d = 0.1; d <= 5.5; d = d + 0.1) { System.out.println(i); } Complex Examples: Any valid expression permitted in the for loops of the Java language are also facilitated in Progranimate this means complex loops can be constructed if needed. Example A: For (x = y +2; x => y+(z*3); x = x * y) { //Code here } Example B: For (anArray[i] = 0 ; anArray[1] <= anotherArray[5]; anArray[i] = anArray[i] + 1 { //Code here } For loop Definition The definition panel for a Java For loop consist of three parameters, the control variable, the condition and the increment. Inline with the rules of the Java language all these parameters are optional. Should the user entry any syntactically incorrect expressions, or non existent variables an error will be presented below the relevant field. Figure 18 The JavaFor Loop Definition Panel
All of the control structures of Progranimate rely on the use of a Boolean expression as a necessity. Boolean expressions are expressions that produce a true or false result when evaluated. Other components such as Print and Assign can also make use of Boolean expressions. This section aims to highlight the possibilities relating to the creation of Boolean expressions in Progranimate. In Progranimate the syntax of any entered expression is native to the programming language selected. In this section, we will look at the creation of expressions in relation to the Java and VisualBasic.Net programming languages. However, this section will be of use to those wishing to use other languages, as there are many similarities between third generation programming languages. The rules regarding the formation of Boolean expressions conform to that of the programming language selected. The main rule that tends to be uniform amongst most third generation programming languages is that the data being compared must be of the same data type. Some languages such as Java and VisualBasic allow for mixed data type comparison. For example, it is okay to compare an Integer with a Double, and visa versa. This ability has also been facilitated in Progranimate (when these languages have been selected). Java permits the comparison of an Integer with a character, via its ASCII code. This feature is not available in Progranimate; it was seen as an unessential feature that it introduced a level of complexity not needed by the novice.
The comparison operators available to Progranimate are in line with the basic operators provided by the selected language. These are shown below in table 8.
Table 8. Comparison operators
Creating simple Boolean expressions in Progranimate is very easy. They are entered when defining or editing one of Progranimate’s control structures (see figure 19). Figure 19. Condition definition Below are some examples of simple logical expressions in the Java and VisualBasic.Net programming languages.
Table 9. Example Boolean expressions For information relating to more complex Boolean expressions, see section 3.9.5.3 ‘Using AND, OR and XOR’ and 3.9.5.4 ‘Complex Boolean expressions.’
Progranimate allows the use of three basic logical operators these are AND, OR and XOR. The form these operators take is dependant on the language selected. Below table 10 shows the logical operators in relation to the Java and VisualBasic.Net programming languages.
Table 10. The logical operators The logical operator NOT is not included in the logical operators used by Progranimate. It is felt more educationally beneficial to for the users to learn how to negate their logic statements, rather than using the NOT operator. Using the thee logical operators the user can construct a very diverse range of Boolean expressions. The examples shown in table 11 below demonstrate some of the possibilities.
Table 11. Examples of Boolean expressions with logical operators
It is possible to use complex Boolean expressions if required. It is permissible to use multiple levels of parenthesise and mathematical sub expressions to build up complex Boolean expressions. However, with novices, the use of complex expressions should be minimised or eliminated, if at all possible. Some examples of what is possible are shown in table 12 below.
Table 12. Examples of complex Boolean expressions
Once an expression is entered into a component, it undergoes evaluation to check for errors. The aim of Progranimate is to inform the user of the error in plain English and to limit the use of technical jargon where possible.
Once entered, an expression is evaluated for syntactical errors. The following ten checks are carried out to validate the expression’s syntax.
There is a very wide rage of syntax errors generated by Progranimate. With respect to syntax error handling, Progranimate aims to be more contextual than most standard development environments. Furthermore, all of the errors generated by Progranimate are in plain English; technical Jargon has been limited where at all possible. Four examples of Progranimate’s syntax errors are shown below. Example 1: A user may attempt to reference a non-existent variable or array when defining a component or structure. In this case, Progranimate should display the following syntax error: The variable X does not exist. Example 2: An error will be generated when a user attempts to enter an unrecognised operator or symbol. For example, using Java’s not equal operator != when VisualBasic.net is selected causes the following error message to appear: != is invalid. Ensure you have typed the expression correctly. Example 3: Look at the following erroneous Java expression. Can you see what is wrong with it? x = x + + 2 Example 4: The user has entered two pluses. This is either because they entered a plus one to many times or because a value is missing between the two plus operators. In any case, the following error message is generated. The symbol + is in an invalid location within the expression.
Each expression entered into Progranimate is evaluated using the normal order of precedence pertaining to the selected Language. When it comes to the order of mathematical expressions, most languages conform to normal mathematical rules of precedence. However, when it comes to the precedence of logical and other operators, the order of precedence may differ very subtlety. Table 13 demonstrates the subtle differences in operator precedence between the Java and VisualBasic.Net languages. During both entry and run time, Progranimate evaluates and calculates its expressions in accordance with the rules of precedence. During entry the expressions are evaluated for validation purposes. During run time, expressions are evaluated so that the variable and array inspectors can be appropriately updated.
Table 13. Operator precedence For precedence relating to the operators of other languages implemented by Progranimate, see the technical documentation relating to that language. It may be worthwhile to take a look on the Internet. For most popular programming languages, the Internet is a great resource for finding information about operator precedence. Directory: docs docs -> Application for acem docs -> Observational Assessment of Teaching Practices Teaching Assessment Initiative Proposal Submitted to The Teachers for a New Era project docs -> Traditional British values docs -> From Warfighters to Crimefighters: The Origins of Domestic Police Militarization docs -> Borzoi Club of America Register of Merit Program I. What is a Register Of Merit docs -> Protecting the rights of the child in the context of migration docs -> United Nations E/C. 12/Esp/5 docs -> 9th May 1950 the schuman declaration docs -> Getting To Outcomes® in Services for Homeless Veterans 10 Steps for Achieving Accountability Download 383.54 Kb. Share with your friends: |