Computer Science
Structured Programming

The approach to programming that is described in the programming guide for C# is called structured programming.

The aim of structured programming is to write programs which are easy to understand and work efficiently. It means observing a few simple conventions in your programming.


When you write a program, you choose the names for the variables, procedures, data structures, the program itself and some other objects. In structured programming, you should choose names which are meaningful and reflect the information that is being stored.

You cannot use spaces in variable names. If you think that you need two words to give a variable a meaningful name, you should use camelCase to make the name readable. For example,

string firstName;
int numberOfRecords;
bool isLastDigit;

Indentation & Layout

All of the code samples in the C# guide show correct indentation. The Visual Studio IDE automatically indents for you, you should not override this.

Indentation provides visual feedback about the structure of a program. It makes it easier to see where control structures start and end.

Procedures & Functions

Most of the techniques for developing algorithms are based on the divide-and-conquer approach. That means that we tend to solve problems by breaking them down into smaller sub-problems that represent a single task or subtask in the pursuit of the solution.

Each of these tasks or subtasks would normally correspond to a procedure or function in a well-written program.

Programs are more readable if each procedure or function performs a single task.

Global Variables

Global variables present a bit of an issue for us in programming. If we have a long, complex program with a number of procedures and lots of global variables, it becomes difficult to keep track of where in the code changes are made to the values stored in global variables. It becomes easier to make mistakes and harder to track down where they occur.

The main solution to this problem is to use parameters in procedures and functions to pass data to the various parts of your program. If needed, we can pass parameters by reference in place of using global variables.

Logical Program Structure

It is possible in most programming languages to add a label to a point in the code and write a GoTo statement to instruct the program to jump to that point. This should always be avoided.

Iteration structures allow us to repeat sections of code as often as required and should be used in place of GoTo statements.