Oct 28

PENGULANGAN (REPETITION/LOOPING)

Pengulangan digunakan untuk menjalankan satu atau beberapa pernyataan sebanyak beberapa kali. Dengan kata lain, pengulangan memungkinkan pengerjaan beberapa kali perintah tetapi penulisan perintah tersebut hanya satu kali.

Struktur pengulangan yang umum digunakan antara lain:

#Pernyataan for

Pernyataan pengulangan for digunakan jika kita sudah tahu berapa kali kita akan mengulang satu atau beberapa pernyataan.

Bentuk umum pernyataan for adalah sbb:

For pencacah := nilai_awal to nilai_akhir do

Aksi

Aksi akan dilakukan sebanyak hitungan pencacah pengulangan, yaitu dari nilai_awal sampai nilai_akhir.

#Pernyataan repeat-until

Pernyataan repeat-until akan melakukan pengulangan aksi hingga kondisi (persyaratan) berhenti terpenuhi.

Bentuk umum pernyataan repeat-until adalah sbb:

Repeat

Aksi

Until kondisi

Tidak seperti pada struktur for yang jumlah pengulangannya diketahui sebelum pengulangan dilaksanakan, maka untuk struktur repeat-until digunakan jika jumlah pengulangan tidak dapat diketahui di awal. Namun yang pasti, pengulangan aksi akan terus dilakukan sampai kondisi berhenti dipenuhi.

#Pernyataan while-do

Sama seperti pada pernyataan repeat-until, pada pernyataan while-do ini digunakan untuk pengulangan yang belum diketahui pasti jumlah pengulangannya. Berakhirnya pengulangan ini ditentukan oleh suatu kondisi. Bila kondisi sudah tidak terpenuhi, maka pengulangan akan berakhir. Dengan kata lain, selama kondisi masih terpenuhi, pengulangan akan terus dilakukan.

Bentuk umum pernyataan while-do adalah sebagai berikut:

While kondisi do

Aksi

Catatan:

Pada pernyataan repeat-until dan while-do, pada dasarnya hampir sama yaitu digunakan jika jumlah pengulangan belum dapat ditentukan. Tetapi terdapat perbedaan yaitu pada pengecekan kondisi. Jika pada pernyataan while-do, kondisi dicek pada awal blok pengulangan, pada pernyataan repeat-until, kondisi dicek pada akhir blok pengulangan.

Perbedaan yang lain, bila pernyataan while-do mengulang pernyataan selama kondisi masih terpenuhi, pernyataan repeat-until mengulang pernyataan selama kondisi belum terpenuhi.

Oct 21

dipertemuan 3 ini membahas :

-Program Control – Selection
-Selection: SWITCH-CASE
-?: Operator
-Go To and Label
-Jenis-jenis Error

Program control

Selection (I)

In order to perform meaningful tasks, it’s common for programs to select some sections of code for execution, and to omit other sections of code. The decision to select or omit sections of code is based on conditions encountered during processing. This type of program control is called selection.

For example, in a program which calculates the quotient of integer pairs, it’s important to avoid division by zero. This means that the program must be able to:
1.identify the condition of a divisor with a value of zero,
2.omit the arithmetic operation, and
3.provide the program’s user with an explanation for the omission.

Following is a program fragment which is able to perform these three tasks. It selects one section of code, and omits another, based on the value stored in the variable divisor.

% Example 1:

put dividend, ” / “, divisor, ” = ” ..

if divisor = 0 then
% handle division by zero:
put ” undefined.”
else
% handle normal case:
put dividend / divisor : 0 : 1
end if

Boolean expressions

Example 1 uses an if statement. if statements begin with the keyword if, followed by a boolean expression and the keyword then.

Boolean expressions have a value of true or false. These values are not strings: they are stored in memory differently, and different operations can be performed with them.

Boolean expressions can be:
•constructed with relational operators, as shown in Example 1,
•used to assign a value to boolean variables, as shown in Example 2, and
•constructed with boolean operators, as shown in Example 3.

% Example 2:

var admissible : boolean
admissible := age > MINIMUM_AGE

% Example 3:

var identityConfirmed : boolean
identityConfirmed := name = “Victoria Windsor”
if not identityConfirmed then
% handle this case
end if

if statement

Using an if statement, we can direct the computer to select one section of code for execution, and to omit other sections of code. An if statement can take one of three forms, as shown below.

Form 1

% Form 1: one true part and no false part

if boolean_expression then
zero or more statements comprising the true” part
end if

When the computer encounters an if statement of Form 1:
1.The computer evaluates the boolean expression.
2.If the boolean expression has the value true, the computer executes the true part.
3.The computer continues execution with the statement which immediately follows the keywords end if.

Form 2

% Form 2: one true part and one false part

if boolean_expression then
zero or more statements comprising the “true” part
else
zero or more statements comprising the “false” part
end if

When the computer encounters an if statement of Form 2:
1.The computer evaluates the boolean expression.
2.If the boolean expression has the value true, the computer executes the true part, and omits the false part.
3.If the boolean expression has the value false, the computer omits the true part, and executes the false part .
4.The computer continues execution with the statement which immediately follows the keywords end if.

Form 3

% Form 3: more than one true part and
% one false part

if boolean_expression_1 then
zero or more statements comprising the
“true” part for boolean_expression_1
elsif boolean_expression_2 then
zero or more statements comprising the
“true” part for boolean_expression_2

elsif boolean_expression_n then
zero or more statements comprising the
“true” part for boolean_expression_n
else
zero or more statements comprising the
“false” part
end if

When the computer encounters an if statement of Form 3:
1.The computer evaluates boolean_expression_1.
2.If boolean_expression_1 has the value true, the computer executes the true part for boolean_expression_1, and omits all other parts.
3.If boolean_expression_1 has the value false, the computer omits the true part for boolean_expression_1, and evaluates boolean_expression_2.
4.If boolean_expression_2 has the value true, the computer executes the true part for boolean_expression_2, and omits all other parts.
5.If boolean_expression_2 has the value false, the computer omits the true part for boolean_expression_2, and evaluates the next boolean expression…
6.If boolean_expression_n has the value true, the computer executes the true part for boolean_expression_n, and omits the false part.
7.If boolean_expression_n has the value false, the computer omits the true part for boolean_expression_n, and executes the false part.
8.The computer continues execution with the statement which immediately follows the keywords end if.

Jenis Jenis Error

Error !, mungkin ini kerap menghantui anda mana kala melakukan kegiatan pemrograman. Nah agar anda bisa memahami lebih lanjut lagi dengan error yang anda temukan, anda harus mengetahui klasifikasi error tersebut.

Pada dasarnya jenis error di klasifikasikan atas 3 jenis, yaitu :
1.Syntax Error
2.Runtime Error
3.Logic Error

1. Syntax Error

Kesalahan jenis ini sangat tergolong mudah untuk di perbaiki. Hal ini di karenakan kesalahan ini akan memunculkan baris yang salah dan bahkan langsung statemen yang salah akan di tampilkan.

Kesalahan jenis ini akan muncul jika program akan di kompilasi atau di jalankan.

Untuk jenis jenis pemrograman yang harus di Kompilasi, kesalahan ini sering terjadi. Tetapi untuk pemrograman yang Interpretasi, atau jenis Interpreter, seperti Visual Basic, VB.Net dan lainnya maka kesalahan jenis ini sudah langsung di perbaiki oleh Interpreternya ataupun langsung di tandai (Mark). Sehingga akan langsung di edit.

2. Runtime Error

Kesalahan jenis ini juga tergolong mudah di perbaiki. Kesalahan ini akan muncul saat program sedang berjalan, jika program yang sedang di jalankan, terjadi error, maka kesalahan akan di tampilkan dan di tujukan pada baris yang salah.

Hmm sangat mudah di perbaiki kan? 😀

3. Logic Error

Nah untuk kesalahan jenis ini, sangat sulit di perbaiki, karna termasuk logika kita atau yang membuatnya yang salah. Sehingga butuh waktu yang lama untuk memperbaikinya. Hal ini dikarenakan logika program terdapat kesalahan.

Kesalahan ini sulit di ketahui, hanya programer programer yang teliti dengan outputnya saja yang bisa mengantisipasi kesalahan ini.

Nah 3 jenis kesalahan sudah saya uraikan satu demi satu, saya mengharapkan anda memahami kesalahan kesalahan yang anda temui di dalam pemrograman.

Oct 14

Operator adalah symbol yang digunakan untuk memproses suatu nilai ke nilai yang berbeda (baru) .

Operant adalah bagian spesifik dari nilai yang dimanipulasi atau yang dioperasikan .

contoh :
A = B + C
dimana A , B , C adalah operand , (+) dan (=) adalah operator

Dalam pelajaran ini, kita mengenal :
##UNARY= Yaitu penghitungan dengan menggunakan 1 operator
##BINARY= Yaitu penghitungan dengan 2 operator
##TRENARY=Yaitu penghitungan dengan 3 operator

contoh operator /binary
binary terdiri dari 2 angka yaitu 1 dan 0
operator mempunyai 6 suboperator yaitu:
1. assignment operator (=, ==)
2. logical operator ( true false true false)
3. bitwise operator (&=and, |=or, ~=complement)
4. pointer operator
5. relational operator (,=>,=<,+)
6. arithmetic operator (matematika gitu +,-,*,/)

contoh perhitungan binary
12 = 1 1 0 0
15 = 1 1 1 1
24 = 1 1 0 0 0
38 = 1 0 0 1 1 0

Oct 7

“Algoritma adalah urutan langkah-langkah logis penyelesaian masalah yang disusun secara sistematis dan logis”. Kata logismerupakan kata kunci dalam algoritma. Langkah-langkah dalam algoritma harus logis dan harus dapat ditentukan bernilai salah atau benar.
Dalam beberapa konteks, algoritma adalah spesifikasi urutan langkah untuk melakukan pekerjaan tertentu. Pertimbangan dalam pemilihan algoritma adalah, pertama, algoritma haruslah benar. Artinya algoritma akan memberikan keluaran yang dikehendaki dari sejumlah masukan yang diberikan. Tidak peduli sebagus apapun algoritma, kalau memberikan keluaran yang salah, pastilah algoritma tersebut bukanlah algoritma yang baik.

Contoh Algoritma dalam kehidupan sehari-hari :
1.Bangun tidur
2.Mandi
3.Makan
4.Beres-beres
5.Pergi Bekerja

Cara mengembangkan algoritma
1.writing > Structure English & Pseudocode
2.Drawing > Flow Chart

Basic Computer Operation:
1.Input
2.Output
3.Compute
4.Storing value to an identifier (Store)
5.Compare
6.Repetition (Loop)

Structure theorem which makes the computer programming possible using only three control structure, which are:
1.Sequence
2.Selection
3.Repetition

Kenapa Menggunakan Bahasa C
Flexibility
Close to low level machine language yet easy to understand

Portability
Used form micro computer to super computer

A Well Known Programming Language
It is used in many forms of implementations such as O/S, scientific application, business application, etc.

Supported With a Large Number of Libraries