Programming Control Structures and Pseudo Code


Some knowledge of any programming language.

Programming Control Structures and Pseudo Code
When it comes to programming (and I am not one per-se to speak of) every language has it's syntax which has certain elements that are unique to that language. However there is a very basic set of concepts concerning program design which generally remains the same for all programming languages. (implementation may vary, also may exclude markup languages such as HTML and CSS to name a few).

These similarities are what are commonly referred to as Control Structures. Control Structures, in any language, help determine the order in which the individual statements, instructions, or function calls of a program are executed or evaluated. Basically telling the computer in what order to process input and display output to obtain the desired result.

This tutorial will go over each of the different control structures and briefly go through the purposes of each.

The different control structures are as follows:
C).IF Conditional statements
D).WHILE conditional statements
E).FOR Conditional statements

These may look like they come from a particular language, and there are statements for many languages that us FOR, WHILE, and IF as loop structures, but these here are general statements representing the structure type in each language.

The input statement is fairly simple. You get input. Whether it's "cin", "scanf" or some other variation of input commands.

The Output is similar only you are outputting information that has been processed by the input and processes in the program. Each output command can vary from one language to the next.

The IF statement is you basic conditional statement. it is used somewhat like this: "IF (variable1 (operator =,<,>,=<,=>,==,!=) variable2) THEN "do this"

Very simple comparison as you can see, however you can run multiple comparisons in some languages which require more complicated, language specific code to carry out such as the switch() command for C++.

The WHILE statement is a conditional loop that executes WHILE a condition is et or true.
EXAMPLE: lets just say you input x and compares it to 10. the program will x++ every time it executes the loop. the code would look something like this:

printf("not there yet!/n");
return 0;

This code first checks whether x is less than 10, which it is, so then the {loop body} is entered, where the printf function is run and x is incremented by 1. After completing all the statements in the loop body, the condition, (x < 10), is checked again, and the loop is executed again, this process repeating until the variable x has the value 10.

This is usually run untill the condition is met.

The FOR loop is probably the most flexible and rightly the most complicated forms of a loop.
The iterations for the FOR loop can be defined before the actual loop happens.

FOR I = 1 TO 10
   REM LOOP body

That is an example of a standard Numeric FOR loop.
a FOR loop is good if you only want to calculate a specified number of times or for specific items only.
you can also specify multiple conditions in a FOR loop as well as the following example outlines:
for (i = 0; i < 10; i++){
    /* loop body */

Pseudo code is basically code that is used to outline the operations of a program so that bugs can be identified before hand and program flow can be established. The syntax of pseudo code is not strict at all and can vary between one program designer and another. The goal is merely getting program flow onto paper so that the initial syntax for the program can be established.

All and all both of these things, standard logic structures and the use of pseudo code can be beneficial in initial program design.