Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

Materi 5 REPETITION CONTROL STRUCTURES Disusun Oleh : Yulyani Arifin,S.Kom, MMSI.

Presentasi serupa


Presentasi berjudul: "Materi 5 REPETITION CONTROL STRUCTURES Disusun Oleh : Yulyani Arifin,S.Kom, MMSI."— Transcript presentasi:

1 Materi 5 REPETITION CONTROL STRUCTURES Disusun Oleh : Yulyani Arifin,S.Kom, MMSI

2 Agenda Struktur DO While Struktur Repeat..Until Struktur Counted Loop

3 Mahasiswa mampu menerapkan struktur kontrol perulangan dalam algoritma. Mahasiswa mampu mengembangkan algoritma dengan menggunakan berbagai variasi struktur kontrol perulangan yang sesuai. Kemampuan Akhir yang Diharapkan

4 MATERI BELAJAR STRUKTUR DO WHILE Ada tiga cara untuk melakukan perulangan tergantung penempatan kondisi perulangan : pada awal Loop(leading decision loop) pada akhir Loop (trailing decision loop) sesuai jumlah perulangan

5 MATERI BELAJAR STRUKTUR DO WHILE Struktur DO WHILE termasuk Leading Decision Loop Ada dua hal penting perlu di perhatikan dalam mengunakan DO WHILE : Kondisi diuji di awal LOOP perlu ada proses inisial untuk set up kondisi sebelum bisa diuji

6 MATERI BELAJAR STRUKTUR DO WHILE Cara untuk menghentikan LOOP adalah dengan membuat kondisi menjadi FALSE artinya dalam proses harus ada statement yang menjadikan kondisi menjadi FALSE

7 MATERI BELAJAR STRUKTUR DO WHILE Latihan : Konversi Farenheit – Celcius Every day, a weather station receives 15 temperature expressed in degrees Fahrenheit. A Program is to be written that will accept each Fahrenheit temperature, convert it to Celcius, and display the converted temperatures to the screen. After 15 temperatures have been processed, the words ‘All temperature processed’ are to be displayed on the screen

8 MATERI BELAJAR STRUKTUR DO WHILE A Diagram Definisi Input F_temp ( 15 temperature) Proses Get Fahrenheit temperatures Convert temperatures Display Celsius temperatures Display screen message Output C_temp (15 temperatures)

9 MATERI BELAJAR STRUKTUR DO WHILE B. Algoritma Solusi Fahrenheit_Celcius_Conversion 1Set temperature_count to zero 2DOWHILE temperature_count < 15 3 Prompt operator for f_temp 4 Get f_temp 5 Compute c_temp = (f_temp – 32) * 5/ 9 6 Display c_temp 7 Add 1 to temperature_count 8ENDDO 9Display “All temperatures processed” to the screen END

10 MATERI BELAJAR STRUKTUR DOWHILE C. DESK CHECKING 1.Data Input 2.Hasil yang diharapkan Data 1Data 2 F_temp3250 Data 1Data 2 C_temp010

11 MATERI BELAJAR STRUKTUR DO WHILE Tabel Check Perintah No Temperatu re_count DOWHILE Condition F_tempC_temp 10 2True 3, Display 11 2True 3, Display 72

12 MATERI BELAJAR STRUKTUR DOWHILE Penggunaan DOWHILE untuk perulangan dengan jumlah yang belum pasti 1. Diulang selama nilai tertentu Co : Print_examination_scores 1Set total_score to zero 2Set total_students to zero 3Read name, exam_score 4DOWHILE exam_score not = 999 5Add 1 to total_students 6Print name, exam_score 7Add exam_score to total_score 8Read name, exam_score 9ENDDO 9IF total_students not = zero THEN average_score = total_score / total_students ENDIF END

13 MATERI BELAJAR STRUKTUR DOWHILE Diulang sampai EOF ^ Jika tidak ada nilai tertentu,perulangan juga bisa diulang sampai tanda EOF. Biasanya tanda EOF muncul saat file baru dibuat atau charater terakhir dalam sebuah FILE. ^ Syntax yang biasa digunakan : - DOWHILE more data - DOWHILE more records - DOWHILE records exists - DOWHILE NOT EOF

14 MATERI BELAJAR STRUKTUR DOWHILE Contoh : A program is required that will read a file of student records and select and print only the records of those students enrolled in a course unit named Programming I. Each student record contains student number, name, address, postcode, gender and course unit number. The course unit number for Programing I is Three totals are to be printed at the end of the report: total females enrolled in the course, total males enrolled in the course and total students enrolled in the course.

15 MATERI BELAJAR STRUKTUR DOWHILE A. DIAGRAM DEFINISI Input Student_record Student_no Name Address Postcode Gender Course_unit Proses Read student records Select student records Print Selected Records Computer total females enrolled Compute total males enrolled Compute total students enrolled Print Totals Output Selected student_records Total_females_enrolled Total_males_enrolled Total_students_enrolled

16 MATERI BELAJAR STRUKTUR DOWHILE B. ALGORITMA SOLUSI Process_student_enrollements 1Set total_females_enrolled to zero 2Set total_males_enrolled to zero 3Set total_students_enrolled to zero 4Read student_records 5DOWHILE record_exist 6 IF course_unit = THEN Print student details Increment total_students_enrolled IF student_gender = Female THEN i ncrement total_females_enrolled ELSE increment total_males_enrolled ENDIF Read Student_records ENDDO 7 Print total_females_enrolled 8 Print total_males_enrolled END

17 MATERI BELAJAR STRUKTUR REPEAT UNTIL Struktur Repeat Until menguji kondisi pada akhir LOOP. Perintah di dalam LOOP minimal akan dikerjakan 1x sebelum kondisi diuji. Jika kondisi = FALSE maka perulangan akan dilakukan sampai kondisi = TRUE.

18 MATERI BELAJAR STRUKTUR REPEAT UNTIL Contoh : Process_student_records Set student_score to zero REPEAT Read student record IF student_number NOT = 999 THEN Write Student_record Increment student_count ENDIF Until student_number = 999 Print student_count END

19 MATERI BELAJAR STRUKTUR COUNTED LOOP Struktur Counted Loop digunakan jika jumlah perulangan sudah diketahui. Proses LOOP dikontrol oleh Index Loop Syntax : DO Loop_Index = initial value to final_value Statement Block ENDDO

20 MATERI BELAJAR STRUKTUR COUNTED LOOP Contoh : Fahrenheit_Celcius_conversion 1 DO temperature_count = 1 to 15 2 Prompt operator for f_temp 3 Get f_temp 4 Compute c_temp = (f_temp – 32)* 5/9 5 Display c_temp ENDDO 6 Display “All temperature processed” to the screen

21 MATERI BELAJAR Q & A


Download ppt "Materi 5 REPETITION CONTROL STRUCTURES Disusun Oleh : Yulyani Arifin,S.Kom, MMSI."

Presentasi serupa


Iklan oleh Google