PhotoSell

Programming



Programming basics
Before we can start the process of programming, we first need to understand what a program is. A program is a set of commands designed to take input, process it and generate output. To do so, a program is usually an implementation of a set of instructions which tells it how exactly to convert the input to output. This set of instructions (or some sets of instructions in some cases) is called an algorithm.
Each programming language has five essential elements, although the syntax varies from language to language, the main idea remains the same. I will describe them briefly as most of you probably know them but I will try to be as detailed as possible for those of you who don’t.
Variables – Variables are used to store and represent data. The data can be simple, such as the name of a person, or complex such as a record of employee in a company holding its name, age, sex and more.
Conditions – Conditions are used in order to execute a set of statements depending on whether a specific condition is satisfied. Let’s take for example a program that reads two numbers from input and check if they are equal. If they are equal we want to execute one set of statements and if not, we want to execute other set of statements.
Loops – Loops are used in order to execute set of commands several times or until a certain condition is met. Usually a programming language contains several types of loops, the most common ones are:
• For – usually used to run a set of commands several times.
• Foreach – usually used to process every element in an array or set of elements.
• While – run until a certain condition is met (condition is checked in the beginning of the loop).
• Do-until – run until a certain condition is met (condition is checked in end of the loop).

Functions and methods – functions are used in order to implement a code reuse. It allows the programmer to put often used code into one location which can then be used over and over again. For example if I want to write a function that checks if a certain number is even or odd I can use a function that gets a number as input and check if it is even or odd. I can then use this function wherever I need to instead of writing the same code over and over again.
Input and Output – input and output enables the program to interact with any data interface. It could be a simple one, such as the keyboard, mouse or files, or even complex data manipulation such as updating database information on a remote server.
Every program probably contains at least one of these basic elements and I can say for sure that most of the programs contain them all. So now that we are familiar with the basics all you have to do is learn how to use these elements to make your program work.