FOR LOOP

For loop will repeat as many times as you specify: for( int x = 0;  x < 5;  x++ ){print x} This loop will run until the condition x < 5 is satisfied and print numbers 0 to 4. One thing that often causes trouble is endless loops. The following code: for( int x =…

LOOPS

Loops let us execute a set of instructions multiple times.There are two frequently used loops: FOR LOOP and WHILE LOOP. You will use FOR LOOP more often but WHILE LOOP is easier to explain. WHILE LOOP  While loop will repeat something WHILE certain condition is true. Notice how we first check the condition  x <…

ARRAYS

Arrays are variables that can hold multiple values.Here we have an array of string values representing each day in a week: string sDays[] = {“Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”, “Sun”} To access an element of a string we need to specify the location (index) of that element. print sDays[4] will output “Fri” because the…

LOGICAL OPERATORS: OR, AND

These are used just as in everyday talk. You can say “I want apple OR orange”, or you can write: string sFruit = “orange”if sFruit == “apple” OR sFruit == “orange” then print “I’ve got a delicious fruit.” In other words, the operator OR will return true if either condition on the left or right…

OPERATORS

Comparison operators are: < , > , <= , >= , == , != When a conditional statement like if is used to determine whether two values are identical most languages use “==” instead of “=” if iFirstNumber == iSecondNumber thenprint “equal”elseprint “not equal”endif Remember the equal operator “==” very well because you will spend…

COMPARING VALUES

To compare values, we need operators. Boolean type plays an important role here. Let’s use two previously defined integer variables containing integers 3 and 5 bool bResult = false bResult  =  iFirstNumber < iSecondNumber print bResult   This code will output “true” because 3 is indeed less than 5, and  operator “<“ returned value true…

DEFINING AND NAMING VARIABLES

Each variable in a program needs to be defined only once.  Notice how I included the letter “i” at the beginning of the variable’s name to signify that variable is of an integer value. This simple trick will always tell you what type each variable is. It will also prevent you from accidentally confusing language’s…

VARIABLES

The most basic building block is a variable. They store values that we use in our program. A variable can hold numbers, text, or logical values “true” and “false”. “sunny” is our variable, and in this case, we can assign it a value of either true or false right above the “If Statement” code, just…

YOUR FIRST PROGRAM

All you need to write a program that every computer will understand are a few commands that are very similar to a short English sentence. Let’s take a look at this example: if sunny then print “have a nice day” else  print “don’t forget your umbrella” endif This fragment of code is a conditional statement…

SOURCE CODE AND COMPILER

What is source code? It is all that text you type to create a program. This is a set of instructions you give to the computer to process and produce the desired result. The compiler is software that has the task of “compiling” your source code into a set of instructions that the computer understands.…