What is the SYNTAXIS in programming? — Programming theory


SYNTAXIS in pro­gram­ming is the set of rules that define the way to write code instruc­tions. Each pro­gram­ming lan­guage has its own syn­tax, that is why it is not con­ve­nient to study pro­gram­ming based pure­ly on writ­ing code, but under­stand­ing the way of think­ing, the basic con­cepts, know­ing the con­trol struc­tures and how to use them; in this way we learn pro­gram­ming inde­pen­dent­ly of the lan­guage and then, depend­ing on the appli­ca­tion, we study the syn­tax of the lan­guage we need, some­thing that can take us a few hours or a day.




Important elements to learn the syntax of a programming language

When we learn the syn­tax of a lan­guage, in gen­er­al we will always fall in the same ele­ments, I will list the most com­mon ele­ments of any pro­gram­ming lan­guage and indi­cate its syn­tax in the par­tic­u­lar case of the C# language.


Com­ments are very impor­tant when pro­gram­ming as they help oth­er team mem­bers under­stand what we are doing, but they are also impor­tant for us as a mem­o­ry aid or as a quick way to inter­pret the code.

Imag­ine work­ing on a project that lasts sev­er­al weeks or months and in which you are going to write dozens of pro­gram­ming scripts, at the time of writ­ing those scripts you under­stand per­fect­ly what is the func­tion that it per­forms, which are the vari­ables and meth­ods; but after a cou­ple of days all that under­stand­ing van­ish­es leav­ing dark­ness behind.

When we need to return to those scripts to apply changes or fix prob­lems, that is, to make the main­te­nance of a soft­ware, it is a prob­lem to under­stand again what func­tion they ful­filled or what the vari­ables were, so it is very help­ful to have com­ments that make this work eas­i­er for us.

In C# you can write a sim­ple com­ment using two slash­es ( // ), every­thing after that will be ignored by the com­pil­er. Longer com­ments require us to indi­cate the start and end of the com­ment, the start is indi­cat­ed by the slash fol­lowed by an aster­isk ( /* ), while the end is indi­cat­ed by the aster­isk fol­lowed by a slash ( */ ), this is also very use­ful for com­ment­ing large sec­tions of code.


Assign­ment is the action of giv­ing a val­ue to a vari­able. The assign­ment oper­a­tor in C# is the equal sign ( = ).

Control Structures

Con­trol struc­tures make it pos­si­ble to mod­i­fy the exe­cu­tion flow of a pro­gram by pro­duc­ing jumps or rep­e­ti­tions in the code.

If Statement

The IF state­ment allows you to make a deci­sion based on a log­i­cal con­di­tion, the syn­tax in C# for an IF state­ment is as follows:

//Intructions to exe­cute if the con­di­tions is true
// Intruc­tions to exe­cute if the con­di­tion is false


The con­di­tion of the if state­ment (in this case boolean­Val­ue) can be any vari­able or instruc­tion that results in a boolean value.

There are some vari­ants of the if state­ment that allow you to ignore braces, but I think that could cause a lot of prob­lems, for exam­ple bugs that are very dif­fi­cult to track, some­thing that can be avoid­ed by sim­ply mak­ing use of curly braces to delim­it the begin­ning and end of each part of the if statement.

IF statement

For Loop

The for loop is a repet­i­tive con­trol struc­ture that allows us to exe­cute a set of instruc­tions a fixed num­ber of times, it is very use­ful for tra­vers­ing col­lec­tions (such as an array) and apply­ing actions to each of the ele­ments. In C# the syn­tax for a for loop is as follows:

for( ini­tial­ize­In­struc­tion; repeat­Con­di­tion ; incre­mentIn­struc­tion){
//Instructions that repeat

A typ­i­cal exam­ple of a for loop can be the following:

for(int i=0; i<n ; i++){
// Instruc­tions that repeat

In the loop above, the iter­a­tion vari­able is i which will ini­tial­ly start at 0, the con­di­tion for the loop to be main­tained is that i is strict­ly less than anoth­er inte­ger vari­able n (which can be the size of an array for exam­ple) and at the end of an iter­a­tion what will be done is an incre­ment of the vari­able i, with the instruc­tion "i++". The instruc­tions that are looped are placed inside braces.

Scroll to Top
Secured By miniOrange