Categories :

Programming basics for dummies Part 2

Another main programming construct that needs to learn the kettle – cycles. The cycle is repeated, the repetition of a certain program block. They are used by programmers are very wide and will almost certainly fall to You in any program code. Let’s say the programmer was given the task to make a table of values of familiar mathematical functions: y = 2x + 1 for integers x in the range from 1 to 10.

Image result for Programming basics for dummies

Such tasks, though because of its simplicity and used to learn the basics of programming by dummies, they are nevertheless very useful for understanding when to apply the cycle – when you need to repeat the same action N times. Every cycle has three characteristics that define his work: the starting value, the ending condition of the loop and increment.

Look at our example calculation table of function values and determine how these characteristics would in our case.

The initial condition of the cycle is the value with which we start to work when you first start the cycle. Because the computation of the function values we start from the minimum value, the initial value of the loop x = 1

The increment is the number by which modifies the value of x in each iteration of the loop. In our example, to graph the function on the points 1, 2, 3, …., 9, 10 use an increment of 1. However, changing the increment can seriously change the work cycle. If, for example, the increment will be 3, then the table will consist of the function values for points 1, 4, 7, 10.

The ending condition of the loop is the sign which tells when to stop the execution of repetitive actions. To count it the value of the function is when the value of x exceeds 10. Therefore, the ending condition of the loop in our case x <=10

For example, here is how to write this basic design programming in free form understandable for dummies.

x = 1 (* initial condition of the cycle *)

UNTIL x <=10 (* loop end *)


y = 2x + 1 (* the action performed in the cycle *)

x = x + 1 (* increment loop *)


Basics of programming functions for dummies

Let us formulate the last basic principle of programming basics for dummies – use features. Functions are blocks of code that can be called repeatedly from anywhere in Your program. Programmers functions are used very widely.

Any function consists of the following components:

Function name – string used when you call (run) and when properly specified the name helps to understand what a function does.

Accept parameters (function arguments) – values, which are used for further calculations or control the behavior of a function when it is called.

The return value is actually what was started, and writing the function is the result of work that can be obtained and used in the further work of the program.

Image result for Programming basics for dummies

Basic principles create functions for programmers-dummies are as follows:

Function combines logically separate piece of code. Ideally, each function should perform a well-defined action, for example to calculate the value of the sine function, to count the number of letters in a row or to capture text to a file.

Usually formed as a function of those parts of the program which are repeatedly used during the execution. This technique reduces the number of lines of code (which makes it easier to understand written program code) and facilitates the editing and making changes to the program.

To control the behavior of the function from the call points use parameters (arguments) when calling the function. It happens that the function creates no accept parameters – this means that it is irrespective of the place of execution of Your program will return the same value (especially for only learning the basics of programming).

The return value is the result of the function. There are functions that return no values, the first stage of such functions it is better not to use – often it is a mistake when designing the programme.

I have listed only the basic principles of programming for dummies, which I hope will help You to make the first steps in this exciting venture.