Introduction to Programming for Laymen

sarkinen.com > johan > Teaching > Programming

8. Programming Constructs

< 7. hello, world - Your First Program 9. Pseudocode >

First, Flow and Functionality of a Program

The basic functionality of any program is - based on some input data - to create some result. That is:

Input (data in) -> Processing -> Results (data out)

Programming Constructs

As we talked about in What Is a Language?, to learn a language you need to learn

In programming languages, we expand on those concepts (fine tune) and use some basic terminology to discuss different building blocks used in programs and programming, called programming constructs (google).

 

Example: A Small Program

To exemplify a few of the constructs just discussed (e.g. comments, constants, variables, control statements, expressions, ...):

/* My small program to calculate the Circumference of a Circle
   i.e. C = pi x D; where 
     C = the Circumference, and 
     D = is the diameter of the circle
*/

pi = 3.14159; // a Constant; and infinitely many more decimals...
  /* Note: not a formal constant as JavaScript doesn't (currently) have that
       construct. */
var diameter; // a Variable; user input

// Next, using an assignment operator, get user input to the variable

do {
  diameter = prompt("Enter diameter (> 0)", 5);
} while (diameter <= 0);

result = diameter * pi; // calculating a result, using an expression
alert( "The circumference of a circle with diameter " + diameter + ' is ' + result );

Press here to run and test this small and simple program.

 

Now, try do the same (slightly simplified) by yourself. Select and copy the text below into Workbench 3L.

pi = 3.14159
var diameter
diameter = prompt('Enter diameter', 5);
results = diameter * pi
alert( "The circumference of a circle with diameter + diameter + ' is ' + result );

What happens? Nothing! Carefully read the code and see if you can find the problems (two different).

Hint 1: variable name

Hint 2: text strings

 

More Resources


< 7. hello, world - Your First Program9. Pseudocode >
Updated 2016-06-02

sarkinen.com | Personnel | Businesses | General/Adm | webmaster | J&P Group (JandP.biz)
Copyright © 1999-2016 J. Sarkinen. All rights reserved.