Opacity: zIndex: Get 100000 0FP0EXP Token to input your own list (json format) or insert json link:

Get 80000 0FP0EXP Token to input your own list (json format) or insert json link:

My Playlist:

JSON Ready: Not Ready

Ready State:

Network State:

Name:

Album:

Reference:

Background Color

General HTML background color:

Header background color:

Menu background color:

Content background color:

Widget background color:

Footer background color:

Font Size

Get 150000 0FP0EXP Token to unlock this feature.

Heading 1 font size:

Heading 2 font size:

Heading 3 font size:

Heading 4 font size:

Heading 5 font size:

Heading 6 font size:

Header font size:

Header Widget font size:

Menu font size:

Widget font size:

Footer font size:

Content font size:

Font Color

Get 200000 0FP0EXP Token to unlock this feature.

Heading 1 font color:

Heading 2 font color:

Heading 3 font color:

Heading 4 font color:

Heading 5 font color:

Heading 6 font color:

Header font color:

Header Widget font color:

Menu font color:

Widget font color:

Footer font color:

Content font color:

Font Shadow

Get 250000 0FP0EXP Token to unlock this feature.

Heading 1 font shadow:

Heading 2 font shadow:

Heading 3 font shadow:

Heading 4 font shadow:

Heading 5 font shadow:

Heading 6 font shadow:

Header font shadow:

Header Widget font shadow:

Menu font shadow:

Widget font shadow:

Footer font shadow:

Content font shadow:

Other Styles Coming Soon



Source Code

Click the above image for basic sourced and click following button for processing token source code.

Ethereum Virtual Machine

Ethereum and EVM (ETC, BSC, AVAX-C-Chain, Polygon, etc).

Telegram Open Network

Telegram Open Network (TON) decentralized application.

Solana

Solana decentralized application.

Tron

Tron decentralized application.

Near

Near decentralized application.

Wax

Wax decentralized application.

Myalgo

Myalgo wallet for Algorand decentralized application.

Sync2

Sync2 wallet for Vechain decentralized application.

Scatter

Scatter wallet for EOS decentralized application.

Ontology

Ontology decentralized application.

Rabbet

Rabbet wallet for Stellar Lumen decentralized application.

Freighter

Freighter wallet for Stellar Lumen decentralized application.

Hivesigner

Hive Signer for Hive decentralized application.

Hivekeychain

Hive Key Chain for Hive decentralized application.

Zilpay

Zilpay wallet for Zilliqa decentralized application.

Neoline N2

Neoline wallet for Neo N2 decentralized application.

Neoline N3

Neoline wallet for Neo N3 decentralized application.

Keplr

Keplr wallet for Cosmos and other decentralized application.

Keeper

Keeper wallet for Waves decentralized application.

IWallet

IWallet for IOST decentralized application.

Starting Computer Programming

Get 60 0FP0EXP Token to remove widget entirely!

source code



source code
old source code

get any 0FP0EXP Token to automatically turn off or 10 0FP0EXP Token to remove this JavaScript Mining.

Get 50000 0FP0EXP Token to remove my NFTS advertisements!

Get 40000 0FP0EXP Token to remove this donation notification!

get 30000 0FP0EXP Token to remove this paypal donation.

View My Stats

Need referral links?

get 20000 0FP0EXP Token to remove my personal ADS.

word number: 9496

Time: 2024-10-02 15:37:44 +0000

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.

Course Outline

Course Overview and Introduction

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.

<html>
<head>
<title>Practice PHP</title>
</head>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
	Username: <input type="text" name="user"><br>
	Password: <input type="text" name="pass"><br>
	<input type="submit">
</form>
<?php 
$username = array("Fajar","John","emanresu");
$password = array("Purnama","Doe","drowssap");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user = $_POST['user'];
$pass = $_POST['pass'];

//var_dump($username[0] == $user and $password[1] == $pass);

for ($c = 0; $c <= count($username)-1; $c++) {

if ($user == $username[$c] and $pass == $password[$c]) {
echo "Welcome!";
break;
} elseif ($c < count($username)-1) {
continue;
} else {
echo "Wrong username or password";
}
}
}

?>
</body>
</html>

Figure 0.1 My practice program in PHP

Learning Objective

This topic would like to cover only the simple part of the technical in programming. We can simply express in Figure 2.

  • It is hoped that you are able to write a simple program and it works.
  • No need to do analysis of the algorithms (efficiency, structures, etc).
  • You are only expected to solve mini problems by making a short script.
  • Ultimately at the end of this course you will be familiar with programming and easily adapt with different programming languages.

C C++ Python Javascript Java Ruby Pascal PHP ...

Figure 0.2 I speak many programming language

Assessment and Measurement

It's up to you of how to do this course but it is recommended to do the following:

  1. Read the contents.
  2. Do the quizzes to enrich your understanding of the content.
  3. Submit assignments whether they are essays or scripts.
  4. Try your programs in virtual programming lab (VPL).
  5. We never meant to place difficult materials so aim for perfect scores before proceeding to the next material since attempting a grade is unlimited.

Once again the top instructions are just our recommendation, do the course as you wish.

  • If your overall score is below 50% you should complete more materials or aim for higher grade.
  • If it's above you are ready to dive into computer programming world.
  • If you got 100% then you should have no problem in adapting or learning new programming languages.

1. About Computer Programming

1.1 Definition

A program is a set of instructions to do certain tasks. On daily life for example a program to turn on a computer:

  1. Plug the cable power.
  2. Turn on the computer.
  3. Turn on the display.
  4. Choose you operating system.
  5. Login.

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:

  1. Pick a food.
  2. Eat food.
  3. Pay for the food.

Or in KFC or McDonalds:

  1. Pick a food.
  2. Pay for the food.
  3. Eat the food.

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!!"

1.2 Application

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.

Windows Calculator Application

Figure 1.2.1 Calculator Application

Libre Office Calc

Figure 1.2.2 Excel application example

Ice Weasel Browser

Figure 1.2.3 Web Browser

1.3 Examples of Programming Language

Below is a list of todays popular programming language. I started with Pascal and C.

  • C
  • C++
  • C#
  • Visual Basic
  • Python
  • R
  • Ruby
  • Perl
  • PHP
  • Java
  • Javascript
  • HTML
  • CSS
  • Ladder Logic
  • Verilog HDL
  • Assembly

1.4 Compilers

1.4.1 Desktop

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.

1.4.2 Browser

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.

1.4.3 Online

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:

1.4.3.1 Note Books

Jupyter Note Book was one of the first, not technically online by default but anyone can host Jupyter Note Books one their servers online:

  • Google Colaboratory: while you can go directly to its website but it is directly available through Google Drive where you can just go to new file and add Google Colab as a new file and you can colaborate with other peers to code here but currently only supports Python.
  • Kaggle Note Book: like Google Colaboratory but optimized for data science.
1.4.3.2 HTML CSS JS

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:

1.4.3.3 Mobile

Mobile programming are heavy in desktop, but there are many online compilers if we just want to try:

1.4.3.4 Pascal
1.4.3.5 C

1.4.4 Smartphone

For Android, we can install Termux or Acode and for iOS we can install Swift Playgrounds.

2. Start Writing

2.1 Note

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:

  1. Operating System (OS): we suggest using Linux because most of the compiler are installed by default, but you may use other like MAC or Windows.
  2. Text editor: anything is ok even the simplest as notepad and wordpad, all that is needed is being able to write the script and save it. Some good example editors with color are VIM, GVIM, Notepad ++, or you may have an editor of certain programming language like Turbo Pascal and Codeblocks.
  3. Compiler: this is the last thing you need, most Linux distribution already equipped with a compiler. If you don't know or don't have the compiler just search on the Internet for Pascal compiler for example. For Windows may asked you to download Turbo Pascal, for Linux mainly Ubuntu or Debian distribution may ask you to install by type "apt-get install fp-compiler". If you want C compiler search on the Internet for C compiler.

2.2 First Script Pseudocode

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

2.3 First Script Flowchart

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")

2.4 First Script in Pascal

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!".

Program HelloWorld;
begin
	writeln('Hello, world!');
end.

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.

program variables;
 
var
	firstname, lastname: string;
	a,b,c,d,e,f,g : integer;
 
begin
	firstname := 'Fajar';
	lastname := 'Purnama';
 
	write('Hi! My name is ', firstname, lastname); writeln('I would like to perform simple math operation');
 
	a := 9;
	b := 4;
	c := a+b;
	d := a-b;
	e := a*b;
	f := a div b;
	g := a mod b;
 
	writeln(a,' + ',b,' = ',c);
	writeln(b,' - ',a,' = ',d);
	writeln(a,' * ',b,' = ',e);
	writeln(b,' div ',a,' = ',f);
	writeln(b,' mod ',a,' = ',g);
end.

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".

program variables;
 
var
	firstname, lastname: string;
	a,b,c,d,e : integer;
	f : real;
 
begin
	write('What is your firstname? '); readln(firstname);
	write('What is your lastname? '); readln(lastname);
 
	write('Hi! My name is ', firstname, lastname); writeln('. I would like to perform simple math operation');
 
	write('Input first number: '); readln(a);
	write('Input second number: '); readln(b);
 
	c := a+b;
	d := a-b;
	e := a*b;
	f := a / b;
 
	writeln(a,' + ',b,' = ',c);
	writeln(a,' - ',b,' = ',d);
	writeln(a,' * ',b,' = ',e);
	writeln(a,' / ',b,' = ',f);
end.

2.5 First Script in C

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!".

#include<stdio.h>

int main() {
	printf("Hello, World!");
	return 0;
}

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.

#include <stdio.h>

int main() {

	char * firstname = "Fajar";
	char * lastname = "Purnama";
	
	printf("Hi!, My name is %s %s.\n", firstname, lastname);
	printf("I would like to do simple math calculation:\n");
	
	int a,b,c,d,e,f,g;
	
	a = 6;
	b = 4;
	c = a + b;
	d = a - b;
	e = a * b;
	f = a / b;
	g = a % b;
	
	printf("%d + %d = %d\n", a, b, c);
	printf("%d - %d = %d\n", a, b, d);
	printf("%d * %d = %d\n", a, b, e);
	printf("%d / %d = %d\n", a, b, f);
	printf("%d mod %d = %d\n", a, b, g);
	
	return 0;
}

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.

#include <stdio.h>

int main () {

	char firstname[20], lastname[20];
	
	printf("What is your first name? "); scanf("%s", firstname);
	printf("What is your last name? "); scanf("%s", lastname);
	
	printf("Hi!, My name is %s %s.\n", firstname, lastname);
	printf("I would like to do simple math calculation:\n");
	
	float a,b,c,d,e,f;
	
	printf("Input first number: "); scanf("%f", &a);
	printf("Input second number: "); scanf("%f", &b);
	
	c = a + b;
	d = a - b;
	e = a * b;
	f = a / b;
	
	printf("%f + %f = %f\n", a, b, c);
	printf("%f - %f = %f\n", a, b, d);
	printf("%f * %f = %f\n", a, b, e);
	printf("%f / %f = %f\n", a, b, f);
	
	return 0;
}	

3. Conditional and Functions

3.1 Note

3.2 Pseudocode

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)

3.3 Flowchart

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

3.4 In Pascal

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.

program simple_login_1;
 
var
	username: string;
 
begin
	write('username: '); readln(username);
 
	if username = 'John' then
	writeln('Hello ', username)
	else
	writeln('Wrong username');
 
	writeln('Program terminate');
end.

Next program if we want more conditions, say that Mary is included as a username:

program simple_login_2;
 
var
	username: string;
 
begin
	write('username: '); readln(username);
 
	if username = 'John' then
	writeln('Hello ', username)
	else if username = 'Mary' then
	writeln('Hello ', username)
	else
	writeln('Wrong username');
 
	writeln('Program terminate');
end.

We can also use "or" for the above program:

program simple_login_2;
 
var
	username, password: string;
 
begin
	write('username: '); readln(username);
 
	if (username = 'John') or (username = 'Mary') then
	writeln('Hello ', username)
	else
	writeln('Wrong username');
 
	writeln('Program terminate');
end.

If we want to include password as well:

program simple_login_4;
 
var
	username, password: string;
 
begin
	write('username: '); readln(username);
	write('password: '); readln(password);
 
	if (username = 'John') and (password = 'Doe') then
	writeln('Hello ', username,' ', password)
	else if (username = 'Mary') and (password = 'Jane') then
	writeln('Hello ', username,' ', password)
	else if (username = 'Fajar') and (password = 'Purnama') then
	writeln('Hello ', username,' ', password)
	else
	writeln('Wrong username or password!');
 
	writeln('Program terminate!');
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.

program simple_login_5;
 
var
	username, password: string;
 
procedure simple_login(username:string; password:string);
	begin
	if (username = 'John') and (password = 'Doe') then
	writeln('Hello ', username,' ', password)
	else if (username = 'Mary') and (password = 'Jane') then
	writeln('Hello ', username,' ', password)
	else if (username = 'Fajar') and (password = 'Purnama') then
	writeln('Hello ', username,' ', password)
	else
	writeln('Wrong username or password!');
 
	writeln('Program terminate!');
	end;
 
begin
	write('username: '); readln(username);
	write('password: '); readln(password);
	simple_login(username, password);
end.

3.5 In C

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.

#include <stdio.h>

int main() {
	int a,b;
	printf("input a value: "); scanf("%d", &a);
	
	if (a == 1) {
	printf("a is equal 1\n");
	} else {
	printf("a is not equal to 1\n");
	}
	
	char string1[] = "test";
	
	b = strncmp(string1, "test", 20);
	printf("b is %d\n", b);
	printf("is b == 0? %d(yes)", b == 0);
	
	return 0;
}

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.

#include <stdio.h>

int main() {

	char username[20];
	printf("Username: "); scanf("%s", username);
	
	if (strncmp(username, "John", 20) == 0) {
		printf("Hello %s.\n", username);
	} else {
		printf("Wrong username!\n");
	}
	
	return 0;
}

Next program if we want more conditions, say that Mary is included as a username:

#include <stdio.h>

int main() {

	char username[20];
	printf("Username: "); scanf("%s", username);
	
	if (strncmp(username, "John", 20) == 0) {
		printf("Hello %s.\n", username);
	} else if (strncmp(username, "Mary", 20) == 0) {
		printf("Hello %s.\n", username);
	} else {
		printf("Wrong username!\n");
	}
	
	return 0;
}

We can also use "or"/"||" for the above program:

#include <stdio.h>

int main() {

	char username[20];
	printf("Username: "); scanf("%s", username);
	
	if ((strncmp(username, "John", 20) ) == 0 || (strncmp(username, "Mary", 20)) == 0) {
		printf("Hello %s.\n", username);
	} else {
		printf("Wrong username!\n");
	}
	
	return 0;
}

If we want to include password as well:

#include <stdio.h>

int main() {

	char username[20], password[20];
	
	printf("Username: "); scanf("%s", username);
	printf("Password: "); scanf("%s", password);
	
	if ((strncmp(username, "John", 20) == 0) && (strncmp(password, "Doe", 20)) == 0) {
		printf("Hello %s %s.\n", username, password);
	} else if ((strncmp(username, "Mary", 20) == 0) && (strncmp(password, "Jane", 20) == 0)) {
		printf("Hello %s %s.\n", username, password);
	} else if ((strncmp(username, "Fajar", 20) == 0) && (strncmp(password, "Purnama", 20)) == 0) {
		printf("Hello %s %s.\n", username, password);
	} else {
		printf("Wrong username or password!\n");
	}
	
	return 0;
}

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.

#include <stdio.h>

void login(char username[20], char password[20]) {

	if ((strncmp(username, "John", 20) == 0) && (strncmp(password, "Doe", 20)) == 0) {
		printf("Hello %s %s.\n", username, password);
	} else if ((strncmp(username, "Mary", 20) == 0) && (strncmp(password, "Jane", 20) == 0)) {
		printf("Hello %s %s.\n", username, password);
	} else if ((strncmp(username, "Fajar", 20) == 0) && (strncmp(password, "Purnama", 20)) == 0) {
		printf("Hello %s %s.\n", username, password);
	} else {
		printf("Wrong username or password!\n");
	}
}
	
int main() {
	char username[20], password[20];
	
	printf("Username: "); scanf("%s", username);
	printf("Password: "); scanf("%s", password);
	login(username, password);
	return 0;
}

4. Arrays and Loops

4.1 Note

4.2 Pseudocode

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

4.3 Flowchart

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)"}}

4.4 In Pascal

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:

program array1;
 
var
	username : array[0..5] of string = ('John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin');
	password : array[0..5] of string = ('Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda');
 
begin
	writeln(username[0]);
	writeln(username[1]);
	writeln(username[3]);
	writeln();
	writeln(password[0]);
	writeln(password[1]);
	writeln(password[3]);
 
end.

Or you may fill them afterward:

program array2;
 
var
	username : array[0..5] of string;
	password : array[0..5] of string;
begin
	username[0] := 'Fajar'; password[0] := 'Purnama';
	writeln(username[0]); writeln(password[0]);
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.

program for_loop;
 
var
	username : array[0..5] of string = ('John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin');
	password : array[0..5] of string = ('Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda');
	i: integer;
 
begin
	for i := 0 to 5 do
	begin
		writeln(i);
	end;
 
	writeln;
 
	for i := 0 to 5 do
		begin
		writeln(username[i], password[i]);
	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).

program many_login;
 
var
	username : array[0..5] of string = ('John', 'Mary', 'Fajar', 'emanresu', 'root', 'admin');
	password : array[0..5] of string = ('Doe', 'Jane', 'Purnama', 'drowssap', 'toor', 'nimda');
	i: integer;
	username_input, password_input: string;
 
begin
	write('Username: '); readln(username_input);
	write('Password: '); readln(password_input);
 
	for i := 0 to 5 do
	begin
 
		if (username_input = username[i]) and (password_input = password[i]) then
		begin
		writeln('Hello ', username_input, ' ', password_input, '!');
		break;
		end
		else if i = 5 then
		writeln('Wrong username or password!');
 
	end;
 
end.

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.

program while_test;
 
var
	a,i: integer;
 
begin

	a := 1;
	write('How much do you want to count? Insert a number: '); readln(i);
	while a <= i do
	begin
		writeln(a);
		a := a + 1;
	end;
 
end.

4.5 In C

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:

#include <stdio.h>

int main() {
	const char * username[] = {"John", "Mary"};
	printf("This is string array: %s %s\n", username[0], username[1]);
	
	const char * password[] = {"Doe", "Jane"};
	printf("This is string array: %s %s\n", password[0], password[1]);
	
	int number[] = {10, 7, 3};
	printf("This is integer array: %d %d %d\n", number[0], number[1], number[2]);
	
	return 0;
}	

Or you may fill them afterward:

#include <stdio.h>

int main() {
	const char * username[6];
	username[0] = "John";
	username[1] = "Mary";
	printf("This is string array: %s %s\n", username[0], username[1]);
	
	const char * password[6];
	password[0] = "Doe";
	password[1] = "Jane";
	printf("This is string array: %s %s\n", password[0], password[1]);
	
	int number[3];
	number[0] = 10;
	number[1] = 7;
	number[2] = 4;
	printf("This is integer array: %d %d %d\n", number[0], number[1], number[2]);
	
	return 0;
}

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.

#include <stdio.h>

int main() {
	const char * username[] = {"John", "Mary", "Fajar", "emanresu", "root", "admin"};
	
	const char * password[] = {"Doe", "Jane", "Purnama", "drowssap", "toor", "nimda"};
	
	int i;
	
	for(i = 0; i <= 5; i++){
		printf("%d\n", i);
	}
	
	for(i = 0; i <= 5; i++){
		printf("This is string array: %s %s\n", username[i], password[i]);
	}
	
	return 0;
}

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).

#include <stdio.h>

int main() {
	const char * username[] = {"John", "Mary", "Fajar", "emanresu", "root", "admin"};
	
	const char * password[] = {"Doe", "Jane", "Purnama", "drowssap", "toor", "nimda"};
	
	char username_input[20], password_input[20];
	
	printf("Username: "); scanf("%s", username_input);
	printf("Password: "); scanf("%s", password_input);
	
	int i;
	
	for(i = 0; i <= 5; i++){
		if((strncmp(username_input, username[i], 20) == 0) && (strncmp(password_input, password[i], 20) == 0)){
		printf("Hello %s %s\n", username_input, password_input);
		break;
		} else if(i == 5) {
		printf("Wrong username or password\n");
		}
	}
	
	return 0;
}

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.

#include <stdio.h>

int main() {
	int i,a;
	a = 1;
	
	printf("How much do you want to count? Insert a number: "); scanf("%d", &i);
	
	while(a<=i){
		printf("%d\n", a);
		a++;
	}
	
	return 0;
}

Others

Paste your code online:

Examples Online: