Introduction To Programming: General Programming Principles

Why do we even want to learn programming languages for Web Design?

While HTML and CSS are the basis for making most web pages, the pages created with these alone are static and incapable of much interactivity. By incorporating other languages such as JavaScript and PHP we can create pages that respond to user input, websites that can be easily updated with new content and other dynamic functionality.

What is a variable?

A variable can be thought of as a box with a label. We can put things in said box, and find them again by looking for the label. We do this because if we were to get something and just leave it lying around it’d get lost and we’d never find it again. We can change the contents of the box after filling it should we so desire — if we could not then the box would represent a constant rather than a variable.

In javascript, there are a few kinds of variable. Most sorts of data are stored simply in var. Boolean Variables, Dates and Arrays require a special syntax to use. var myDate = new Date is the syntax for a date variable, and the other special variables follow the same pattern.

In many programming languages the type of data to be stored in a variable must be defined at creation. Unlike javascript, where in most cases the type of data is automatically implied by what you put in the variable, languages such as C++ require you to declare the variable as a data type such as string, integer, or double, amongst others. Those of you who have begun working with Access should find the concept of Data Types familliar.

What are Control Structures?

Control Structures are the ways that we can control the flow of a program. Usually a program will go through it’s instructions one after the other, just reading through the lines in order. With control structures we can make it skip over parts, or go back and do parts over again.

There are two main types of Control Structure: Conditions (such as ‘if’ statements) and Loops.

Conditions are used where something should only happen if something else is true (or false). Form validation, where an alert is only given when a field is incorrectly filled (of not filled at all) is one use of a condition.

Loops (alternatively Repetition or Iteration) is used where identical or similar code blocks need to be used many times in a row. Some tasks require many passes to complete, such as sorting a list. These require virtually the same instructions to be run time after time. By using a loop we can have a program keep on going through the same block until the task is complete.

There is a third control structure — the Jump, which is used to redirect the program to a specific line. It is not used in modern programming — Conditions and Loops are enough for any program, and Jumps make code much harder to understand.

Leave a Reply

Avatars are handled by the Gravatar service