1 / 41

TO DO!!!

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 )

Download Presentation

TO DO!!!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TO DO!!! • COBALAHContoh program padaslide3-18dibawahini,pahamidancatat/tuliskanperbedaannya. • TUGASLatihanpada slide ke 19 no 1,2,3,5, Dikerjakan 1 kelompokdua orang (satubangku) YANG DIKUMPULKANHARIINIADLHTUGAS NO.1 (SOFTCOPY) DI BAAK (1 orang mengkoordinirdikumpulkandlm 1 folder) SEDANGKAN NO.2 DIKUMPULKANPEKANDEPAN

  2. Lesson 3 – PernyataanBerulang WHILE-DO REPEAT UNTIL FOR

  3. WHILE Banyakperulanganbelumdketahui FOR Digunakan untuk perulangan yang sudah diketahui berapa kali akan dilakukan REPEATE Idem While pemeriksaankondisiboolean di awal, sedangrepeate di akhir

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

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

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

  7. 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(‘jumlahputarannya = ‘ ,k); writeln(‘magelang’); End. 4

  8. While-do dengankondisiboolean 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

  9. While-do dengankondisiboolean Program putaran_while_do_karakter; Uses wincrt; Varkar : char; Begin clrscr; writeln(‘putaran while dengantipekarakter’); kar:='a'; while kar <=‘m’ do begin writeln(kar); kar :=succ (kar); End; writeln; Readln; End. 6

  10. While-do dengankondisijamak 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(‘jumlahputaran =‘ ,k); writeln(‘Nilai A =’ ,A); writeln(‘Nilai B=’ ,B); A:=succ(A); B=succ(B); k:=succ (K); End; writeln; Readln; End. 7

  11. REPEAT UNTIL Repeat Statement; … Until condition;

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

  13. I := 11; While I <= 10 Do Begin Writeln(‘STMIK'); Inc(I); End; Dan I := 11; Repeat Writeln(‘STMIK'); Inc(I); Until I <= 10; 9

  14. Padacontoh 1, tidakakanmencetakapa-apa, sedangkanpadacontoh 2 akanmencetaktulisanSTMIKminimal 1 kali. • Padaprinsipnyastruktur While melakukanpemeriksaanawal, danstrukturRepeat melakukanpemeriksaan di akhir.

  15. FOR-TO / DOWNTO-DO For variabel := nilaiawalTo nilaiakhirDo Statement; For variabel := nilaiawalDownTonilaiakhirDo Statement;

  16. Uses wincrt; VarI : Integer; Begin For I := 1 To 10 Do Writeln(‘STMIK'); End. Uses wincrt; VarI : Integer; Begin For I := 10 DownTo 1 Do Writeln(‘STMIK'); End. 10

  17. Break, continue, randomize Uses wincrt; Var 1:integer; begin I := 1; While I <= 10 Do Begin Writeln(‘STMIK'); I := I + 1; Break; End; End.

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

  19. Break, continue, randomize num:=random(50) variabelnummungkinberisisalahsatubilangan0 s/d 49. Uses wincrt; var i : byte; begin randomize; for i:=1 to 10 do write(random(30),' '); end.

  20. LATIHAN 1. Buatlah program yang menghasilkan output: 1 2 3 4 5 6 2. Output 123454321

  21. 3.Output 12345 12345 12345 12345 12345 4. Output 12345 23451 34512 45123 51234 5. Output 1 12 123 1234 12345

  22. 6. Output 11111 22222 33333 44444 55555 7.Output 1 22 333 4444 55555 8. Output 1 121 12321 1234321 123454321 12344444321 1233333333321 122222222222221 11111111111111111 9. Output 11111 12221 12321 12221 11111

  23. IF THEN If conditon Then Statement1 Else Statement2;

  24. Uses wincrt; Var Bilangan : Integer; Begin Clrscr; Write(‘MasukanBilangan ? ‘); Readln(Bilangan); If (Bilangan Mod 2) = 0 Then Writeln (‘Genap’) Else Writeln (‘Ganjil’); Readln; End.

  25. 1 If condition1 Then Statement1 Else If condition2 Then Statement2 Else If condition3 Then Statement3 Else Statement4;

  26. 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';

  27. 2 CasevariabelOf Range1 : Statement1; Range2 : Statement2; Range3 : Statement3; … Else StatementN; End;

  28. Case nilaiof 80..100: grade:='A'; 70..79 : grade:='B'; 60..69 : grade:='C'; 50..59 : grade:='D'; Else grade:='E'; End;

  29. If-then jamak If ((tahun Mod 4) = 0) And Not (tahun Mod 100 = 0)) Or(tahun Mod 400) = 0 Then Writeln (‘TahunKabisat !’) Else Writeln (‘BukanTahunKabisat !’);

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

  31. TAMBAHAN Special Reserved Words of the CRT/WINCRT Unit Turbo Pascal menyediakan suatu unit CRT, yang berisi perintah-perintah pengaturan layarsepertimembersihkanlayar, mengaturwarnatulisan, warna background, memindahkanposisi cursor, mode layar, danmembuat window

  32. Examples :    • Clrscr; • GotoXy(_,_); • Textbackground(); • Textcolor(); • Readkey; • Delay(); • Halt; / Halt()

  33. Example of each Clrscr: (clear screen) writeln('When you press enter, the screen would be cleared!');readln;clrscr;

  34. 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;

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

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

  37. Untukcrt Textbackground(word/int): (Background colour); Textbackground(red); {word - red}Writeln('Note the difference');Textbackground(5); {integer - 5}ClrScr;Writeln('Note the difference'); Readln;

  38. Untukcrt Textcolor(word/int): (Text colour); Textcolor(red); {word - red}Writeln('Text colour');Textcolor(5); {integer - 5}Writeln('Text colour'); Readln;

  39. Untukcrt Delay(int): (Waits for some time); Writeln('1');Delay(1000);{1000 milliseconds}Writeln('2');Delay(1000);Writeln('3');Readln;

More Related