What is the SYNTAXIS in programming? – Programming theory

Definition

SYNTAXIS in programming is the set of rules that define the way to write code instructions. Each programming language has its own syntax, that is why it is not convenient to study programming based purely on writing code, but understanding the way of thinking, the basic concepts, knowing the control structures and how to use them; in this way we learn programming independently of the language and then, depending on the application, we study the syntax of the language we need, something that can take us a few hours or a day.

A SHORT BREAK WITH THE LATEST NEWS

CONSIDER SUBSCRIBING!


LET'S CONTINUE WITH THE ARTICLE

Important elements to learn the syntax of a programming language

When we learn the syntax of a language, in general we will always fall in the same elements, I will list the most common elements of any programming language and indicate its syntax in the particular case of the C# language.

Comments

Comments are very important when programming as they help other team members understand what we are doing, but they are also important for us as a memory aid or as a quick way to interpret the code.

Imagine working on a project that lasts several weeks or months and in which you are going to write dozens of programming scripts, at the time of writing those scripts you understand perfectly what is the function that it performs, which are the variables and methods; but after a couple of days all that understanding vanishes leaving darkness behind.

When we need to return to those scripts to apply changes or fix problems, that is, to make the maintenance of a software, it is a problem to understand again what function they fulfilled or what the variables were, so it is very helpful to have comments that make this work easier for us.

In C# you can write a simple comment using two slashes ( // ), everything after that will be ignored by the compiler. Longer comments require us to indicate the start and end of the comment, the start is indicated by the slash followed by an asterisk ( /* ), while the end is indicated by the asterisk followed by a slash ( */ ), this is also very useful for commenting large sections of code.

Assignment

Assignment is the action of giving a value to a variable. The assignment operator in C# is the equal sign ( = ).

Control Structures

Control structures make it possible to modify the execution flow of a program by producing jumps or repetitions in the code.

If Statement

The IF statement allows you to make a decision based on a logical condition, the syntax in C# for an IF statement is as follows:

if(booleanValue){
//Intructions to execute if the conditions is true
}else{
// Intructions to execute if the condition is false

}

The condition of the if statement (in this case booleanValue) can be any variable or instruction that results in a boolean value.

There are some variants of the if statement that allow you to ignore braces, but I think that could cause a lot of problems, for example bugs that are very difficult to track, something that can be avoided by simply making use of curly braces to delimit the beginning and end of each part of the if statement.

IF statement
🟢

PLEASE SUBSCRIBE

For Loop

The for loop is a repetitive control structure that allows us to execute a set of instructions a fixed number of times, it is very useful for traversing collections (such as an array) and applying actions to each of the elements. In C# the syntax for a for loop is as follows:

for( initializeInstruction; repeatCondition ; incrementInstruction){
//Instructions that repeat
}

A typical example of a for loop can be the following:

for(int i=0; i<n ; i++){
// Instructions that repeat
}

In the loop above, the iteration variable is i which will initially start at 0, the condition for the loop to be maintained is that i is strictly less than another integer variable n (which can be the size of an array for example) and at the end of an iteration what will be done is an increment of the variable i, with the instruction “i++”. The instructions that are looped are placed inside braces.

Secured By miniOrange