This section would like to introduce computer programming to starters, and for those who would like to dive into the world of programming. No advance topic will be covered here, instead focuses on wide of simple and easy programmings. We understand that you might not master the basics of programming after reading all the materials, but we expect you to have ideas of what materials you have read when you want to write a program. The author for example knows that he/she needs to use "if else" and "for" in his/her simple login program, but still searches on the Internet for the correct syntax in using those functions. Each programming language like Pascal, C, C++, Python, and Ruby had their own form of syntax but the pattern is similar, more ever the idea is still the same.
This section would like to introduce computer programming to starters, and for those who would like to dive into the world of programming. No advance topic will be covered here, instead focuses on wide of simple and easy programmings. If you ever saw a program, or someone programming and it is hard, it's because you have never started in programming. It happens to me too, when someone just suddenly shows his program which hurts my eyes. I started learning programming which only contains 5 lines, then little by little increase the amount that I have wrote. The program that used to give me headache on Figure 1, now it's simple program that I could write.
Figure 0.1 My practice program in PHP
This topic would like to cover only the simple part of the technical in programming. We can simply express in Figure 2.
Figure 0.2 I speak many programming language
It's up to you of how to do this course but it is recommended to do the following:
Once again the top instructions are just our recommendation, do the course as you wish.
A program is a set of instructions to do certain tasks. On daily life for example a program to turn on a computer:
There are variety of ways to do stuffs, and it's same with a program. That's why there tends to be many programs out there but do similar tasks. Usually programs tends to be unique for each people writing them, since they have their own ways. For example eating at a food court, you can:
Or in KFC or McDonalds:
So a computer program is defined as a set of instructions that does specific things when executed by a computer. For example command 'printf("Hello World!!")' in C language will output a text display "Hello World!!"
With computers today lots tasks are being helped by computers. They have done lots of things on our behalf for example on Figure 1.2.1 a calculator program that does calculation for us in a very short time. Figure 1.2.2 is an excel to perform tabulations where we can arrange our data or informations in form of tables. It can even perform calculations and other processes. Last example on Figure 1.2.3 is a web browser which is an application we used to surf the Internet for informations.
Figure 1.2.1 Calculator Application
Figure 1.2.2 Excel application example
Figure 1.2.3 Web Browser
Below is a list of todays popular programming language. I started with Pascal and C.
Almost all compilers are by default on desktop and therefore just search online for the programming language you want to learn and download. The browser alone is a compiler for Hyper Text Markup Language (HTML), Cascading Style Sheets (CSS), JavaScript (JS), and other web programming languages. Depending on the Operating System (OS), its command line interface have a built-in programming language for example Windows have Powershell, Linux have Bash, and MacOS have Z Shell.
As stated before, the browser such as Edge, Firefox, Chrome, Opera, etc., is a web programming language compiler and Internet is not required. Just write a HTML, CSS, and JS files and run on the browser. Take a look at my JavaScript programming section.
Today often there is no need to install compilers to learn programming languages because many online services provides online compilers. Only when we are seriously building a program we install compilers locally. I will try to update a list of online compilers:
Jupyter Note Book was one of the first, not technically online by default but anyone can host Jupyter Note Books one their servers online:
Although the browser is enough, but if you do not want to save the files on your hard storage and/or share your codes online:
Mobile programming are heavy in desktop, but there are many online compilers if we just want to try:
For Android, we can install Termux or Acode and for iOS we can install Swift Playgrounds.
There are many tutorials already available online if you want to start learning a programming language, but here we will try to give you a point of where to start, provide a comfortable track until you become familiar with beginner programming. I started with Pascal then C, so this will be first example for every content. Examples are written in various programming language (in the future we would like to make it available in all programming language). If you want to start quickly I suggest viewing the content that had online compiler available (NOTE: Online compiler coming soon!!). (Python, PHP, Ruby, C++ coming soon)
Following suggest setting up environments if you want to do programming at you own computer but you may skip to next section if don't want the hassle and later on you may come back here. The programmings that will be cover are freeware or opensource so programming like Visual Basic or Matlab will not be covered here. What you need for this course are:
Pseudocode is in freeform where currently there are not defined rules. The only concept is make the pseudocode as easiest to understand as possible.
Simplest "Hello World!" code.
INPUT: None
PROCESS: None
OUTPUT: PRINT "Hello, world!"
Including variables code.
INPUT: None
INITIALIZE:
firstname = "Fajar"
lastname = "Purnama"
a = 9
b = 4
OUTPUT:
PRINT "Hi! My name is " + firstname + lastname
PRINT "I would like to perform simple math operation"
PROCESS:
c = a + b
d = a - b
e = a * b
f = a DIV b
g = a MOD b
OUTPUT:
PRINT c
PRINT d
PRINT e
PRINT f
PRINT g
Including user input code.
INITIALIZE:
firstname
lastname
a
b
INPUT:
READ firstname
READ lastname
OUTPUT:
PRINT "Hi! My name is " + firstname + lastname + ". I would like to perform simple math operation"
INPUT:
READ a
READ b
PROCESS:
c = a + b
d = a - b
e = a * b
f = a / b
OUTPUT:
PRINT c
PRINT d
PRINT e
PRINT f
For flowchart, each boxes have different functions and try to minimize the arrows.
flowchart TD Rectangle["Rectangle (Process)"] Parallelogram[/"Parallelogram (Input/Output)"/] Rhombus{"Rhombus (Decision)"} Hexagon{{"Hexagon (Preparation)"}} Trapezoid[/"Trapezoid (Document)"\] Circle(("Circle (Terminal)")) Ellipse(["Ellipse (Terminator)"])
Simplest "Hello World!" flowchart.
flowchart TD Start("Start") --> HelloWorld[/"Hello, world!"/] HelloWorld --> End("End")
Including variables flowchart.
flowchart TD Start("Start") --> Initialize{{"firstname = ''Fajar''; lastname = ''Purnama''; a = 9; b = 4"}} Initialize --> Output1[/"OUTPUT(''Hi! My name is '' + firstname + lastname + ''I would like to perform simple math operation'')"/] Output1 --> Process["c = a + b; d = a - b; e = a * b; f = a DIV b; g = a MOD b"] Process --> Output2[/"OUTPUT(c, d, e, f, g)"/] Output2 --> End("End")
Including user input flowchart.
flowchart TD Start("Start") --> Initialize{{"firstname, lastname : string; a,b,c,d: integer; f: float;"}} Initialize --> Input1[/"INPUT(firstname, lastname)"/] Input1 --> Output1[/"OUTPUT(''Hi! My name is '' + firstname + lastname + ''I would like to perform simple math operation'')"/] Output1 --> Input2[/"INPUT(a, b)"/] Input2 --> Process["c = a + b; d = a - b; e = a * b; f = a DIV b;"] Process --> Output2[/"OUTPUT(c, d, e, f, g)"/] Output2 --> End("End")
Here's a link to one of online pascal compiler provided by http://www.tutorialspoint.com/compile_pascal_online.php. You can search the Internet for online compilers. The code for now is not colored, we suggest copy and pasting the code into an online compiler, or your editor if supports color like GVIM and Notepad ++. The "Hello World!" script is very famous in programming world to be as the first program to write. The goal of the program is to produce an output "Hello World!".
If you use the online compiler from tutorialspoint, overwrite the script, compile and execute. If you're using Linux save the file into "hello.pas" for example and write "fpc hello.pas". It will produce an executable file "hello" you type "./hello" to run the file.
The next lesson is using variables. We can define a variable as a boolean, number, string, and many other variables. It's recommended to copy, paste, run the script, and see its output first. That way is easier than thoroughly identifying the code first. The program example below is defining "firstname" and "lastname" as a string with the value of "firstname" is "Fajar" and "lastname" is Purnama. Then a variable from "a" to "g" is defined as integer with "a" and "b" initialized. Then we perform simple math operation.
The last of this section is using user input. If the previous script we manually define "firstname", "lastname", "a", and "b", next we let the user define them after the program is run. Simply use the syntax "read" or "readln".
Here's a link to one of online C compiler provided by http://www.tutorialspoint.com/compile_c_online.php. You can search the Internet for online compilers. The code for now is not colored, we suggest copy and pasting the code into an online compiler, or your editor if supports color like GVIM and Notepad ++. The "Hello World!" script is very famous in programming world to be as the first program to write. The goal of the program is to produce an output "Hello World!".
If you use the online compiler from tutorialspoint, overwrite the script, compile and execute. If you're using Linux save the file into "hello.c" for example and write "gcc hello.c -o hello". It will produce an executable file "hello", then type "./hello" to run the file.
The next lesson is using variables. We can define a variable as a boolean, number, string, and many other variables. It's recommended to copy, paste, run the script, and see its output first. That way is easier than thoroughly identifying the code first. The program example below is defining "firstname" and "lastname" as a string with the value of "firstname" is "Fajar" and "lastname" is Purnama. Then a variable from "a" to "g" is defined as integer with "a" and "b" initialized. Then we perform simple math operation.
The last of this section is using user input. If the previous script we manually define "firstname", "lastname", "a", and "b", next we let the user define them after the program is run. Simply use the syntax "scanf". For the numbers we have to change for "a" to "&a" and so. That's covered in advance topic for now.
The following is the simplest conditional program. If the input is "John" it will output "Hello John", if not it will output "Wrong Username".
INITIALIZE:
username: string;
INPUT:
username
PROCESS:
Is username = "John"?
OUTPUT:
if yes, print "Hello " + username, else print "Wrong username".
Next program if we want more conditions, say that Mary is included as a username:
INITIALIZE:
username: string;
INPUT:
username
PROCESS:
Is username = "John"?
OUTPUT:
if yes, print "Hello " + username, and EXIT conditional.
if no, go to next condition process.
PROCESS:
Is username = "Mary"?
OUTPUT:
if yes, print "Hello " + username, else print "Wrong username".
We can also use "or" for the above program:
INITIALIZE:
username: string;
INPUT:
username
PROCESS:
Is username = "John" or "Mary"?
OUTPUT:
if yes, print "Hello " + username, else print "Wrong username".
If we want to include password as well:
INITIALIZE:
username: string;
password: string;
INPUT:
username, password;
PROCESS:
Is username = "John" and password = "Doe"?
OUTPUT:
if yes, print "Hello " + username, and EXIT conditional.
if no, go to next condition process.
PROCESS:
Is username = "Mary" and password = "Jane"?
OUTPUT:
if yes, print "Hello " + username, else print "Wrong username and password".
Say this program is used on many pages or included in other programs. Should we paste the whole code? we can, but we prefer to refer this program as a procedure. There's another famous term called function, similar with only difference it returns a value.
INITIALIZE:
username: string;
password: string;
INPUT:
username, password;
PROCEDURE login(username, password):
PROCESS:
Is username = "John" and password = "Doe"?
OUTPUT:
if yes, print "Hello " + username, and EXIT conditional.
if no, go to next condition process.
PROCESS:
Is username = "Mary" and password = "Jane"?
OUTPUT:
if yes, print "Hello " + username, else print "Wrong username and password".
END PROCEDURE
PROCESS and OUTPUT:
login(username, password)
The following is the simplest conditional program. If the input is "John" it will output "Hello John", if not it will output "Wrong Username".
flowchart TD Start("Start") --> Initialize{{"username"}} Initialize --> Input[/"INPUT(username)"/] Input --> Login{"Is username = ''John''?"} Login -->|yes|OutputYes[/"OUTPUT(''Hello '' + username)"/] Login -->|no|OutputNo[/"OUTPUT(''Wrong username'')"/] OutputYes --> End("End") OutputNo --> End
Next program if we want more conditions, say that Mary is included as a username:
flowchart TD Start("Start") --> Initialize{{"username"}} Initialize --> Input[/"INPUT(username)"/] Input --> Login1{"Is username = ''John''?"} Login1 -->|yes|Output1Yes[/"OUTPUT(''Hello '' + username)"/] Login1 -->|no|Login2{"Is username = ''Mary''?"} Login2 -->|yes|Output1Yes[/"OUTPUT(''Hello '' + username)"/] Login2 -->|no|OutputNo[/"OUTPUT(''Wrong username'')"/] Output1Yes --> End("End") OutputNo --> End
We can also use "or" for the above program:
flowchart TD Start("Start") --> Initialize{{"username"}} Initialize --> Input[/"INPUT(username)"/] Input --> Login{"Is username = ''John'' or ''Mary''?"} Login -->|yes|OutputYes[/"OUTPUT(''Hello '' + username)"/] Login -->|no|OutputNo[/"OUTPUT(''Wrong username'')"/] OutputYes --> End("End") OutputNo --> End
If we want to include password as well:
flowchart TD Start("Start") --> Initialize{{"username"}} Initialize --> Input[/"INPUT(username, password)"/] Input --> Login1{"Is username = ''John'' and password = ''Doe''?"} Login1 -->|yes|Output1Yes[/"OUTPUT(''Hello '' + username)"/] Login1 -->|no|Login2{"Is username = ''Mary'' and password = ''Jane''?"} Login2 -->|yes|Output1Yes[/"OUTPUT(''Hello '' + username)"/] Login2 -->|no|OutputNo[/"OUTPUT(''Wrong username and password'')"/] Output1Yes --> End("End") OutputNo --> End
Say this program is used on many pages or included in other programs. Should we paste the whole code? we can, but we prefer to refer this program as a procedure. There's another famous term called function, similar with only difference it returns a value.
flowchart TD Start("Start") --> Initialize{{"username"}} Initialize --> Input[/"INPUT(username, password)"/] Input --> LoginProcedure[["Login(username, password)"]] LoginProcedure --> End("End") StartLoginProcedure("Start Login(username, password)") --> Login1{"Is username = ''John'' and password = ''Doe''?"} Login1 -->|yes|Output1Yes[/"OUTPUT(''Hello '' + username)"/] Login1 -->|no|Login2{"Is username = ''Mary'' and password = ''Jane''?"} Login2 -->|yes|Output1Yes[/"OUTPUT(''Hello '' + username)"/] Login2 -->|no|OutputNo[/"OUTPUT(''Wrong username and password'')"/] Output1Yes --> EndLoginProcedure("End Login(username, password)") OutputNo --> EndLoginProcedure
The following is the simplest conditional program. If the input is "John" it will output "Hello John", if not it will output "Wrong Username". We personally think that no need for more explanation, just try the programs. This course is designed simple, explanations are for more advance materials. In Pascal ":=" gives a value to a variable while "=" compares whether "a" is equal to "b". It will return TRUE if correct and FALSE if incorrect.
Next program if we want more conditions, say that Mary is included as a username:
We can also use "or" for the above program:
If we want to include password as well:
Say this program is used on many pages or included in other programs. Should we paste the whole code? we can, but we prefer to refer this program as a procedure. There's another famous term called function, similar with only difference it returns a value.
Doing the simple login on C is not as simple as Pascal because of the string factor, but first we want to show that the concept of if else remains the same. The program states if the user input "1" it will say "the value is 1", if not it will say "the value is not 1". At the end of the program we use the function strncmp to compare strings since the usual method doesn't work. If the compare string is the same "string1 == test" then it will output 0. The final input in strncmp "20" is the max number of character, you may change it as you want.
The following is the simplest conditional program. If the input is "John" it will output "Hello John", if not it will output "Wrong Username". We personally think that no need for more explanation, just try the programs. This course is designed simple, explanations are for more advance materials. In C "=" gives a value to a variable while "==" compares whether "a" is equal to "b". It will return "1" (TRUE) if correct and "0" (FALSE) if incorrect. C seems intimidating at first, but in our experience, if we learn C, we can easily adapt to different programming languages.
Next program if we want more conditions, say that Mary is included as a username:
We can also use "or"/"||" for the above program:
If we want to include password as well:
Say this program is used on many pages or included in other programs. Should we paste the whole code? we can, but we prefer to refer this program as a void. There's another famous term called function, similar with only difference it returns a value.
This is not a formal definition but we see array as place to store many values. If you assign a variable as an array it may store many numbers, names, values, etc. For example we store the username and password into the array first hand:
INITIALIZE:
username = ['John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin'];
password = ['Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda'];
OUTPUT:
username[0]; (will output John)
username[1]; (will output Mary)
username[3]; (will output emanresu)
password[0]; (will output Doe)
password[1]; (will output Jane)
password[3]; (will output drowssap)
Or fill afterwards.
INITIALIZE:
username = [];
password = [];
PROCESS:
username[0] = "Fajar"
password[0] = "Purnama"
OUTPUT:
username[0]; (will output Fajar)
password[0]; (will output Purnama)
If we have many username and password, and we want to write a login script as in section 3 it will be very difficult. Instead why not the machine do it program? In other words we write a program telling the machine to automatically write the script. Our method here is using the loop method as following.
INITIALIZE:
username = ['John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin'];
password = ['Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda'];
i: integer;
PROCESS and OUTPUT:
for i from 0 to 5 do
PRINT[i]; (will print from 0 - 4);
endfor
PROCESS and OUTPUT:
for i from 0 to 5 do
PRINT(username[i], password[i]); (will print username and password from array 0 - 4 one by one);
endfor
The program above uses for loop up to 6x (0-5), the first for loop shows that the value if "i" changes in order from 0 to 5 every iteration, and the next for loop shows we can call the username and password using shorter script. Next let's implement the section 3 login script (again copy, paste, and try the program first for easier approach).
INITIALIZE:
username = ['John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin'];
password = ['Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda'];
i, j: integer;
INPUT:
username_input;
password_input;
PROCESS and OUTPUT:
j = array size of username (or password);
for i from 0 to j do
if username_input equals to username[i] and password_input equals to password[i] then
Print("Hello " + username[i]);
Terminate for loop;
endif
if i equals to j then
Print("Wrong username and password");
endif
endfor
The code above uses "begin" and "end" if we want to put more statement inside the if else. The "break" function forcefully ends the for loop if the correct username and password has been found. On the other hand if the for loop already on it's last iteration "5" and no username and password had been found, it will write "Wrong username or password". Other than For there's also While, maybe more at other programming language. "For" specifies the number of iterations, while "while" sets a goal which the process will not stop until it reaches its goal.
INITIALIZE:
username = ['John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin'];
password = ['Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda'];
i, j: integer;
INPUT:
username_input;
password_input;
PROCESS and OUTPUT:
i = 0;
j = array size of username (or password);
while i does not equal j
if username_input equals to username[i] and password_input equals to password[i] then
Print("Hello " + username[i]);
Terminate while loop;
endif
if i equals to j then
Print("Wrong username and password");
endif
i = i + 1;
endwhile
This is not a formal definition but we see array as place to store many values. If you assign a variable as an array it may store many numbers, names, values, etc. For example we store the username and password into the array first hand:
flowchart TD Start("Start") --> Initialize{{"username = ['John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin']; password = ['Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda'];"}} Initialize --> Output[/"OUTPUT(username[0];username[1];username[3];password[0];password[1];password[3];)"/] Output --> End("End")
Or fill afterwards.
flowchart TD Start("Start") --> Initialize{{"username = []; password = [];"}} Initialize --> FillArray["username[0] = fajar; password[0] = purnama;"] FillArray --> Output[/"OUTPUT(username[0];password[0];)"/] Output --> End("End")
If we have many username and password, and we want to write a login script as in section 3 it will be very difficult. Instead why not the machine do it program? In other words we write a program telling the machine to automatically write the script. Our method here is using the loop method as following.
flowchart TD Start("Start") --> Initialize{{"username = ['John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin']; password = ['Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda']; i = 0; j = size of array username (or password)"}} Initialize --> Output[/"OUTPUT(username[i];password[i];)"/] Output --> Loop{"Has i equals to j?"} Loop -->|no|IterateLoop["i = i + 1"] IterateLoop --> Output Loop -->|yes|End("End")
The program above uses for loop up to 6x (0-5), the first for loop shows that the value if "i" changes in order from 0 to 5 every iteration, and the next for loop shows we can call the username and password using shorter script. Next let's implement the section 3 login script (again copy, paste, and try the program first for easier approach).
flowchart TD Start("Start") --> Initialize{{"username = ['John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin']; password = ['Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda']; i = 0; j = size of array username (or password)"}}
This is not a formal definition but we see array as place to store many values. If you assign a variable as an array it may store many numbers, names, values, etc. For example we store the username and password into the array first hand:
Or you may fill them afterward:
If we have many username and password, and we want to write a login script as in section 3 it will be very difficult. Instead why not the machine do it program? In other words we write a program telling the machine to automatically write the script. Our method here is using the loop method as following.
The program above uses for loop up to 6x (0-5), the first for loop shows that the value if "i" changes in order from 0 to 5 every iteration, and the next for loop shows we can call the username and password using shorter script. Next let's implement the section 3 login script (again copy, paste, and try the program first for easier approach).
The code above uses "begin" and "end" if we want to put more statement inside the if else. The "break" function forcefully ends the for loop if the correct username and password has been found. On the other hand if the for loop already on it's last iteration "5" and no username and password had been found, it will write "Wrong username or password". Other than For there's also While, maybe more at other programming language. "For" specifies the number of iterations, while "while" sets a goal which the process will not stop until it reaches its goal.
This is not a formal definition but we see array as place to store many values. If you assign a variable as an array it may store many numbers, names, values, etc. For example we store the username and password into the array first hand:
Or you may fill them afterward:
If we have many username and password, and we want to write a login script as in section 3 it will be very difficult. Instead why not the machine do it program? In other words we write a program telling the machine to automatically write the script. Our method here is using the loop method as following.
The program above uses for loop up to 6x (0-5), the first for loop shows that the value if "i" changes in order from 0 to 5 every iteration, and the next for loop shows we can call the username and password using shorter script. Next let's implement the section 3 login script (again copy, paste, and try the program first for easier approach).
The "break" function forcefully ends the for loop if the correct username and password has been found. On the other hand if the for loop already on it's last iteration "5" and no username and password had been found, it will write "Wrong username or password". Other than For there's also While, maybe more at other programming language. "For" specifies the number of iterations, while "while" sets a goal which the process will not stop until it reaches its goal.
Paste your code online:
Examples Online: