Professional Documents
Culture Documents
ITFPlusEBook (FC0 U61) Module2 - Unit3
ITFPlusEBook (FC0 U61) Module2 - Unit3
Say hello back to !
"mailto: support@comptia.org> The tags tell a client application (such as a browser) how to structure the document = htm1—this top-level parent element identifies the type of document. All the other tags are nested within this one. Page 150m= body—indicates the main part of the content as a page to show to the Programming and App client. HTML files can also have head sections, which would not be shown Doveloument as part of the page display. = h1—indicates that the content is a heading level. = p-indicates the content is a paragraph-level block. = a~indicates that the content links to another resource. In the example, this is an email address, but it could be another section of the page or another file or a page on another web server. Note that each tag has a start and close element. Programming Concepts In order to write a program using a particular programming language, you must first understand the structure and syntax of the language. Most programming languages share similarities in their structure and syntax, but itis important to use the specific syntax correctly as any errors will cause the code not to compile or run. Without discussing the specifics of any particular language, the following topics list some of the basic building blocks and structures used. Identifiers An identifier is used in a program to access a program element, such as a stored value, class, method, or interface. For example, you might assign the identifier FirstName to a stored value that contains a user's first name. In essence, an identifier is a label for something within your program. If your identifier stores data, then it will be either a variable or a constant. Variables variable contains a value that can change during the execution of the program. This value might be a text string, a number, or any other data type. gv Variables are usually declared, defined as a particular data type, and given an initial value at the start of the routine in which they are used. Itis often possible to use undeclared variables, but this can make code harder to read and more prone to errors. Using our example of a first name, it's important to understand that although a erson’s name might not change, if you use a programmatic technique to refer to a user's name without knowing which user you're referring to, then, as far as the program is concemed, that is a variable. You can assign a value to a variable using fairly simple code. Poge 151Mociule 2/ Unit 3 Poge 152 For example, the following pseudocode declares our FirstName variable to store a string value with an initial value Andy, then sets it to a value from a data store: declare FirstName as String = "Andy" FirstName = find LastLoggedonUser and get FirstNme print FirstName Running this code might produce the following output James Constants A constant is a specific identifier that contains a value that cannot be changed within the program. For example, you might want to store the numerical value for the screen dimensions or resolution Containers Container can be used as a term for a special type of identifier that can reference multiple values (or elements). One example of a container construct is a simple array. For example, say that you want your program to store a list of user names who have logged on to the computer in the last 24 hours. You would declare the array with the data type of the values it will contain and the number of elements or "tows" that the array can contain: declare Logons(9) as string gv Elements in the array are counted from zero so the Logons(9) array contains up to 10 elements. The following pseudocode would add a value to the first element in the array’ Logons(0) = find LastLoggedonUser and get FirstName In this example, the array has a single dimension, Arrays can also be multidimensional, which you can visualize as like a table with multiple columns. Note that all the elements must be the same data type. For example, the following code creates a two-dimensional array: declare Logons(9,1) as string The following pseudocode would populate the first "row' in the array, with the first name going into the first column and the logon time into the second: Logons (0,0) = find LastLoggedonUser and get FirstName Logons(0,1) = find LastLoggedonUser and get Time One of the limitations of the array container type is that it cannot be resized. Most programming languages support container types called vectors that can grow or shrink in size as elements are added or removed.Branches ‘Programming and Apo Your program runs from the start to the end unless you instruct it to deviate from this path. One way of doing so is to create a branch; this is an instruction to your computer to execute a different sequence of instructions. You use branches to control the flow within your program. For example, you might create a branch based on a condition. We saw this in our earlier example when we verified a number had been entered correctly. Ifit had, then something happened, and if it had not, then something else happened. This is a conditional branch. For example, in the following pseudocode, the value of a variable called DisplayNumber is compared to 25. if DisplayNumber is greater than 25, then a variable called Count is incremented by 1. If DisplayNumber is less than 25, no action occurs and the variable Count remains the same. If DisplayNumber > 25 Then Count = Count+1 End If Loops Loops are similar to branches in as much as they deviate from the initial program path according to some sort of logic condition, However, with a loop, you instruct your computer to perform, or repeat, a task until a condition is met. For example, you might create a loop that continues until a certain amount of time has elapsed or until a counter reaches a certain level. Then, a predetermined action might occur, depending upon what you want. In the following example, the program loops around until the value of iis 5. Then the program proceeds to the next statement. For i = 1 to 5 print 4 Next As well as "For" structures, loops can also be implemented by "While" statements: Do While i <= 100 ieaed print i Loop g ‘As mentioned above, you need to make sure your code does not contain unintended or infinite loops. Without the statement to increment 3 in the Do loop example above, the loop would continue forever. An infinite loop will make the process hang. Page 153Mociule 2/ Unit 3 Poge 154 Operators Looping and branching structures depend on logical tests to determine whether to continue the loop or the branch to follow. A logical test is one that resolves to a TRUE or FALSE value. You need to be familiar with basic comparison operators is equal to (retums TRUE if both conditions are the same) = is not equal to =