Professional Documents
Culture Documents
K2 Mte3113
K2 Mte3113
MTES3113
Struktur Kawalan/
Control Structure
Basically
commands in
code form
… Java, COBOL,
Arahan/Perintah FORTRAN,
pada asasnya PASCAL, BASIC,
dalam bentuk Visual Basic,
PYTHON
kod
1
13/1/2020
Is used when
Cetak Print
instruction is based
on rows
Tamat End
Start
Start
Output “ Enter the
Output “ Enter your radius value:”
name:”
Input radius
Input name
Compute
Output “ Hello” + Circle Area =
name PI*radius*radius
End
Kenyataan dilakukan
mengikut keadaan/syarat
(syarat ialah benar atau
Start palsu)
Output “ Enter the Statement is executed
radius value:”
based on the condition if it
Input radius is true or false
Compute
Circle Area = Digunakan apabila mahu
PI*radius*radius
membuat keputusan dalam
Output “Circle Area = perjalanan sesuatu
“ + answer
program (mungkin
End mengakibatkan lompatan)
Is used when needed to
make a decision (maybe it
may cause a jump) @DL IPGKPP 2020
@DL IPGKPP 2020
2
13/1/2020
Menggunakan simbol
pilihan
Uses a decision symbol Adakah
benar Papar Is sum
hasil
“Gagal” <10?
<10?
KP tunggal, KP dwipilihan true
Kenyataan “if……”
Jika keadaan benar tindakan dilakukan
Jika keadaan palsu, tindakan dilangkau
“if……” statement
If condition true, action will be taken
If condition false, action will skip
Kenyataan “if/else”
Tindakan berbeza jika keadaan benar atau palsu
“if/else” statement
Different action if condition is true or false
@DL IPGKPP 2020 @DL IPGKPP 2020
Kenyataan “switch”
true
Membolehkan satu pemboleh ubah untuk diuji case a case a
action(s)
break
default
action(s)
3
13/1/2020
KU “UNTUK”
IC “FOR”
Adalah lebih baik untuk melaksanakan satu Ini dapat dilaksanakan dengan satu struktur
operasi berulang dengan menulis kod untuk ulangan, yang lebih dikenali sebagai satu
operasi tersebut sekali dan kemudian loop
letakkannya dalam struktur supaya memaksa This can be completed withone iteration
komputer mengulanginya sebanyak kali yang structure, which is better known as a loop
perlu daripada menulis kod ikut kawalan
jujukan.
Program Payroll untuk pekerja.
• perlu lakukan langkah yang sama untuk setiap orang pekerja
It is better to implement one iteration • Menyelesaikan masalah begini memerlukan satu struktur yang
operation by writing a code for the operation diulangi satu set arahan/kenyataan sebanyak kali yang perlu
once and then put it inside the structure so Workers Payroll Program.
that it forces the computer to repeat it as • Needs to repeat the same steps for each worker
many times needed then to write a code • Solving problem like this required one structure where a set of
following a sequence control command/statements is repeated as many times needed.
Adakah Is the
nombor benar number True
positif? positive?
Tamat End
palsu False
4
13/1/2020
true
is executed, then all executed again
until condition becomes false
Statement(s)
(loop-body)
Next
Statement @DL IPGKPP 2020 @DL IPGKPP 2020
true
product <= 1000 product = 2 * product
false
@DL IPGKPP 2020 @DL IPGKPP 2020
Next
Statement
@DL IPGKPP 2020 @DL IPGKPP 2020
5
13/1/2020
Statement(s)
Format
do { true
Continue
statement condition?
Next
Statement