Programming Essentials: Basic data types and control structures

S Ruiz de Aguirre
3 min readDec 7, 2020

If you have never programmed before, or your experience is limited to dynamic-typed languages such as R, Python or JavaScript, it is always nice to jump back into the basics for programming.

So what exactly do we mean by data types? It’s the way our compiler or interpreter will treat the data and the operations it will allow us to do with it. For example, the + and * operators work in an entirely different fashion with strings than how they work with numbers.

In traditional (static) languages such as C++, Java or Visual Basic, you will commonly see a type declaration when instancing any new variable, for example.

String x = "Hello World!";

Dynamic languages such as Python or Javascript will try to interpret a variable’s type when declaring it, there is no need to express the type.

So what variable types exist?

We will separate them between primitives and composites (i.e. types that derive from others).

Primitives are as follows:

  • Booleans are binary data. You can think of them as off-on, 0–1, Ground State-Excited State, or any other binary; however, in most languages these will be False or True.
  • Integers are the Z set of numbers. Depending on the programming language, they may or may not accept negatives.
  • Floating point numbers are as close as the computer can get to the set of real numbers. Precission may vary for floating points but commonly they will be of two variants: float and double.

Ennumerations can help us associate an integer value with any other abstract data type, and we can also associate any integer with a character (think of ASCII or Unicode), this allows us to think about composites:

  • Characters are any piece of text, including whitesace and symbols.
  • Strings are concatenations of more than one character, they are effectively an array of characters, i.e. “Hello” would be equal to [“H”, “e”, “l”, “l”, “o”], and every character in a string can be addressed by its position in the string starting from 0.
  • Since strings are essentially vectors (also known as arrays or lists) we could generalize this for all data types. The most general structure would be the array, which can be n-dimensional and is an organized manner of storing data. Depending on the language arrays may or may not be able to hold different data types within them. Additionally, there are subcategories from arrays suh as tuples (immutable arrays) and sets (arrays that cannot have repeated elements).

The most common control structures are if/else statements and loops. Since this is just a basic overview, I’ll plug in flowcharts and explain briefly.

Sequence (step by step action) vs selection (if/else) and iteration.

If/Else statements will set up two or more potential actions according to a condition (there is a more general but also more limited structure called switch).

Iterations will run a loop as long as a condition is met, the most common loops are for, for each and while.

  • A while loop will check a condition every time and break out of the loop until it is not met. While loops can result in infinite loops if not correctly coded.
  • For loops provide a value that will be modified in every iteration until a certain condition is met, a common case would be
for( int i = 0; i < 20; i++){
print(i)
}
  • The structure is for(initialization, condition, action to perform at the end of each iteration), and everything inside the block will be executed.
  • For each loops (known as each loops in some languages, and integrated to for in others) will apply any actions on the loop to each element in an array or collection object.

--

--