Upload presentasi
Presentasi sedang didownload. Silahkan tunggu
Diterbitkan olehIdris Alfa Telah diubah "10 tahun yang lalu
1
TO DO!!! COBALAH Contoh program pada slide 3-18 dibawah ini, pahami dan catat/tuliskan perbedaannya. TUGAS Latihan pada slide ke 19 no 1,2,3,5, Dikerjakan 1 kelompok dua orang (satu bangku) YANG DIKUMPULKAN HARI INI ADLH TUGAS NO.1 (SOFTCOPY) DI BAAK (1 orang mengkoordinir dikumpulkan dlm 1 folder) SEDANGKAN NO.2 DIKUMPULKAN PEKAN DEPAN
3
Lesson 3 – Pernyataan Berulang
WHILE-DO REPEAT UNTIL FOR
4
WHILE Banyak perulangan belum dketahui
REPEATE Idem While pemeriksaan kondisi boolean di awal, sedang repeate di akhir FOR Digunakan untuk perulangan yang sudah diketahui berapa kali akan dilakukan
5
WHILE DO 1 Program putaran_while_do; Uses wincrt; Var k:integer; Begin clrscr; k:=0; while k<10 do writeln(‘stmik’); k:=k+1; writeln(‘bina patria’); writeln(‘magelang’); End. 1
6
2 Program putaran_while_do; Uses wincrt; Var k:integer; Begin clrscr; k:=0; while k<10 do begin writeln(‘stmik’); End; k:=k+1; writeln(‘bina patria’); writeln(‘magelang’); End. 2
7
3 Program putaran_while_do; Uses wincrt; Var k:integer; Begin clrscr; k:=0; while k<10 do begin writeln(‘stmik’); k:=k+1; End; writeln(‘bina patria’); writeln(‘magelang’); End. 3
8
4 Program putaran_while_do; Uses wincrt; Var k:integer; Begin clrscr; k:=0; while k<10 do begin writeln(‘stmik’); k:=k+1; writeln(‘bina patria’); End; writeln(‘jumlah putarannya = ‘ ,k); writeln(‘magelang’); End. 4
9
While-do dengan kondisi boolean
Program putaran_while_do_boolean; Uses wincrt; Var k:integer; Benar : boolean; Begin clrscr; benar:=true; k:=0; while benar do begin writeln(‘stmik’); k:=k+1; benar:=(k>10); writeln(‘bina patria’); End; writeln(‘magelang’); End. 5
10
While-do dengan kondisi boolean
Program putaran_while_do_karakter; Uses wincrt; Var kar : char; Begin clrscr; writeln(‘putaran while dengan tipe karakter’); kar:='a'; while kar <=‘m’ do begin writeln(kar); kar :=succ (kar); End; writeln; Readln; End. 6
11
While-do dengan kondisi jamak
Program putaran_while_do_jamak; Uses wincrt; Var k, A,B : integer; Begin clrscr; A:=1; B:=0; k:=1; while (A<5) and (B<5) do begin writeln(‘jumlah putaran =‘ ,k); writeln(‘Nilai A =’ ,A); writeln(‘Nilai B=’ ,B); A:=succ(A); B=succ(B); k:=succ (K); End; writeln; Readln; End. 7
12
Repeat Statement; … Until condition;
REPEAT UNTIL Repeat Statement; … Until condition;
13
Program putaran_repeat_until; Uses wincrt; Var k:integer; Begin Clrscr; K:=0; Repeat writeln(‘stmik’); k:=k+1; Until k>10; Writeln (‘bina patria’); Writeln (‘magelang’); Readln; End. 8
14
I := 11; While I <= 10 Do Begin Writeln(‘STMIK'); Inc(I); End; Dan Repeat Until I <= 10;
9
15
Pada contoh 1, tidak akan mencetak apa-apa, sedangkan pada contoh 2 akan mencetak tulisan STMIK minimal 1 kali. Pada prinsipnya struktur While melakukan pemeriksaan awal, dan struktur Repeat melakukan pemeriksaan di akhir.
16
FOR-TO / DOWNTO-DO For variabel := nilai awal To nilai akhir Do Statement; For variabel := nilai awal DownTo nilai akhir Do Statement;
17
Uses wincrt; Var I : Integer; Begin For I := 1 To 10 Do Writeln(‘STMIK'); End.
Uses wincrt; Var I : Integer; Begin For I := 10 DownTo 1 Do Writeln(‘STMIK'); End. 10
18
Break, continue, randomize
Uses wincrt; Var 1:integer; begin I := 1; While I <= 10 Do Begin Writeln(‘STMIK'); I := I + 1; Break; End; End.
19
Break, continue, randomize
Uses wincrt; Var 1:integer; begin I := 1; While I <= 10 Do Begin 20 Writeln(‘STMIK'); I := I + 1; Continue; End; End.
20
Break, continue, randomize
num:=random(50) variabel num mungkin berisi salah satu bilangan 0 s/d 49. Uses wincrt; var i : byte; begin randomize; for i:=1 to 10 do write(random(30),' '); end.
21
LATIHAN 1. Buatlah program yang menghasilkan output: 2. Output
22
3.Output 12345 4. Output Output
23
6. Output Output 8. Output Output
24
If conditon Then Statement1 Else Statement2;
IF THEN If conditon Then Statement1 Else Statement2;
25
Uses wincrt; Var Bilangan : Integer; Begin Clrscr; Write(‘Masukan Bilangan ? ‘); Readln(Bilangan); If (Bilangan Mod 2) = 0 Then Writeln (‘Genap’) Else Writeln (‘Ganjil’); Readln; End.
26
1 If condition1 Then Statement1 Else If condition2 Then Statement2 If condition3 Then Statement3 Statement4;
27
if mark>=80 then grade:='A' else { 79 or below goes here } if mark>=70 then grade:='B' else { 69 or below goes here } if mark>=60 then grade:='C' else { 59 or below goes here } if mark>=50 then grade:='D' else { 49 or below goes here } grade:='E';
28
2 Case variabel Of Range1 : Statement1; Range2 : Statement2; Range3 : Statement3; … Else StatementN; End;
29
Case nilai of 80. 100: grade:='A'; 70. 79 : grade:='B'; 60
Case nilai of : grade:='A'; : grade:='B'; : grade:='C'; : grade:='D'; Else grade:='E'; End;
30
If-then jamak If ((tahun Mod 4) = 0) And Not (tahun Mod 100 = 0)) Or (tahun Mod 400) = 0 Then Writeln (‘Tahun Kabisat !’) Else Writeln (‘Bukan Tahun Kabisat !’);
31
LATIHAN OUTPUT = * age < 2 ==> "You are a baby !" * 2 to age < 12 ==> "You are a kid !" * 12 to age < 18 ==> "You are a teenager !" * 18 to age < 24 ==> "You are a young adult !" * 24 to age < 40 ==> "You are an adult !" * 40 to age < 55 ==> "You are middle aged !" * 55 to age < 65 ==> (Give comments yourself) * age to 65 ==> (Give comments yourself)
32
Special Reserved Words of the CRT/WINCRT Unit
TAMBAHAN Special Reserved Words of the CRT/WINCRT Unit Turbo Pascal menyediakan suatu unit CRT, yang berisi perintah-perintah pengaturan layar seperti membersihkan layar, mengatur warna tulisan, warna background, memindahkan posisi cursor, mode layar, dan membuat window
33
Examples : Clrscr; GotoXy(_,_); Textbackground(); Textcolor(); Readkey; Delay(); Halt; / Halt()
35
Example of each Clrscr: (clear screen)
writeln('When you press enter, the screen would be cleared!'); readln; clrscr;
36
Gotoxy(int,int): (Go to position x and y); gotoxy(10,10); Writeln('The position is 10 pixels from the left of the screen, and ten pixels from the top of the screen'); readln;
37
Readkey: (Reads a key-press);
Example 1: Writeln('Press ANY key!!!'); Readkey; Example 2: Writeln('Press ANY key'); Keypress := readkey; {keypress is a DECLARED string variable(can be an integer variable)} Writeln(Keypress);
38
Halt(int): (Program terminates with an exit code);
writeln('Press enter and the program terminates!); Readln; Halt(0); Note that instructions following 'halt' are not executed since the program terminates when halt is encountered.
39
Untuk crt Textbackground(word/int): (Background colour);
Textbackground(red); {word - red} Writeln('Note the difference'); Textbackground(5); {integer - 5} ClrScr; Writeln('Note the difference'); Readln;
40
Untuk crt Textcolor(word/int): (Text colour); Textcolor(red); {word - red} Writeln('Text colour'); Textcolor(5); {integer - 5} Writeln('Text colour'); Readln;
41
Untuk crt Delay(int): (Waits for some time); Writeln('1'); Delay(1000);{1000 milliseconds} Writeln('2'); Delay(1000); Writeln('3'); Readln;
Presentasi serupa
© 2024 SlidePlayer.info Inc.
All rights reserved.