All programming languages share the same concept. In most cases, it will be easy for a programmer that uses one language to learn another language because despite the differences in rules and conventions, they all have the same basic way of processing data. These basic concepts include variables, conditionals, and loops. Let's take a quick look at each of them.
Variables
The term variable refers to something that varies in value. This definition still holds true in programming terms. In computer programming, a variable is an entity used to represent a quantity (number) or other forms of data (string, Boolean, etc.).
Programming languages have their own rules when it comes to naming variables. For example, in Perl and PHP, all variables must begin with a dollar ($) symbol. The next character must be a letter or an underscore. In Java, variable names can begin in a letter, an underscore, or a dollar symbol. Other programming languages have similar naming rules and conventions.
When working with variables, one also has to consider the data types. Data types are the different forms of data used and processed in a program. Commonly, data types are numbers, characters or strings, Boolean, and objects (for object-oriented programming languages).
Some languages, like Java and C++, are strict when it comes to variable's data types. When programming in these languages, you'll have to define the variable and specify the data type it will contain before using it within the program. Unlike in other programming languages, PHP for example, you can instantly use a variable without the need to define it and its data type.
Variable assignment is a statement that gives a value to a certain variable. Programming languages have very similar way of assigning values to variables and that is the use of the equal sign (=).
Conditionals
Conditionals give computer programs the power to decide. A program that uses a conditional will perform one action for one certain situation, and perform a different one for another situation. Basically, when writing conditionals in programs, the programmer defines all possible situations and gives the program a specific instruction to execute for each of these situations.
Here's a very simple instruction. Say the program has to output the month name depending on the user's input, which will be the month number. The programmer will write the program so that when the user inputs 1, the output should be "January, "February" when the input is 2, and so on.
The most commonly used conditional statement present in all high level programming languages is the "if-else" statement. A basic "if-else" statement includes one condition and two blocks of code instructions. If the condition is satisfied, one set of instruction will be executed, otherwise, the other block will be executed.
Another conditional statement present in many programming languages is the "switch" statement". A "switch" statement can be implemented using a set of "if-else" statements but "switch" is often used for shorter code and readability. A switch statement has a test subject and a set of "cases". If the test subject's value matches one case, the block of statement for that corresponding case will be executed.
Loops
In writing computer programs, in many cases, repetition will be required. That is, a set of instructions will be executed repeatedly until a certain condition is met. These types of statements are called "loops".
An example of a basic program containing a loop will be a simple counter. This program will have a variable (the counter) with an initial value (zero, for example). The program will add one to the current value of the counter until a certain number is reached (ten, for example). In this case, the condition will be "Is the counter variable's value equal to ten?". The program will continue and repeatedly add one to the counter's current value until this condition is met. When the condition is met, the program will stop executing.
The "while loop" is a loop statement present in all high level programming languages. This statement contains two elements, a condition and a set of instructions. But unlike in our example, a "while loop" will continue to execute the set of instructions as long as the condition is satisfied. The loop will terminate once the condition becomes false, thus, the term "while". But with a little creativity, the example above can still be implemented using "while".
Another common loop statement present in all high level programming languages is the "for" loop. A "for" loop statement is designed to function just like a while loop but using shorter and more readable code, just like what the "switch" condition is to the "if-else" statement. But like the "switch" statement, "for" loops have several limitations. In cases where a loop cannot be implemented with "for", "while is used".
A person having a good understanding of these three concepts in one programming language will make it easy for him to learn another programming language.
Comments ( 0 )