Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pemrograman VisualMinggu …5… Page 1 MINGGU Ke Lima Pemrograman Visual Pokok Bahasan: Control Statement II Tujuan Instruksional Khusus: Mahasiswa dapat.

Similar presentations


Presentation on theme: "Pemrograman VisualMinggu …5… Page 1 MINGGU Ke Lima Pemrograman Visual Pokok Bahasan: Control Statement II Tujuan Instruksional Khusus: Mahasiswa dapat."— Presentation transcript:

1

2 Pemrograman VisualMinggu …5… Page 1 MINGGU Ke Lima Pemrograman Visual Pokok Bahasan: Control Statement II Tujuan Instruksional Khusus: Mahasiswa dapat menjelaskan dan mengaplikasikan konsep control statement II pada Visual Basic 2008 Referensi: Deitel Deitel, Visual Basic 2008 (2009), How to Program, Prentice Hall. Chapter 6

3 Pemrograman VisualMinggu …5… Page 2 Agenda For... Next Repetition Statement Do... Loop while Repetition Statement Do... Loop Until Repetition Using Exit in Repetition Statements Using Continue in Repetition Statements Logical Operator

4 Pemrograman VisualMinggu …5… Page 3 For/Next Repetition Structure Statements For {kondisi awal} to {kondisi akhir} step value {numbers} Statements Next Statements

5 Pemrograman VisualMinggu …5… Page 4 Example of For Next Repetition Module modForCounter Sub Main() Dim counter As Integer For counter = 2 To 10 Step 2 Console.Write(counter & " ") Next Console.Readkey() End Sub End Module Result:

6 Pemrograman VisualMinggu …5… Page 5 Select Case Multiple-Selection Structure Select Case {variable} Case {value} Case {value awal} to {value akhir} Case {value}, {value awal} to {value akhir} End Select

7 Pemrograman VisualMinggu …5… Page 6 Example of Select Case Multiple-Structure Module Module1 Sub Main() Dim grade As Integer Console.Write("Masukan Total Nilai Akhir :") grade = Console.ReadLine() Select Case grade Case 100 Console.Write("Perfect") Case 85 To 99 Console.Write("Very Good") Case 75 To 84 Console.Write("Good") Case 65 To 74 Console.Write("Enough") Case 55 To 64 Console.Write("Bad") Case Else Console.Write("Very Bad") End Select End Sub End Module

8 Pemrograman VisualMinggu …5… Page 7 Do/Loop While Repetition Structure Statements Do Statements Loop While {kondisi} Statements The Do…Loop While Statement is similar to the Do While…Loop statement, except that the loop continuation Condition is tested after the loop body is performed; therefore, in a Do…Loop While statement, the loop body is always executed at least once.

9 Pemrograman VisualMinggu …5… Page 8 Example of Do/Loop While Repetition Module Module1 Sub Main() Dim counter As Integer = 1 Do Console.Write(counter & " ") counter += 1 Loop While counter <= 5 Console.Readkey() End Sub End Module Result:

10 Pemrograman VisualMinggu …5… Page 9 Do/Loop Until Repetition Structure Do Statements Loop Until {kondisi} Statements The Do…Loop until repetition statement is similar to the Do Until…Loop statement, except that the loop-termination condition is tested after the loop body is performed; therefore, the loop body executes at least once.

11 Pemrograman VisualMinggu …5… Page 10 Example of Do/Loop Until Repetition Module Module1 Sub Main() Dim counter As Integer = 1 Do Console.Write(counter & " ") counter += 1 Loop Until counter > 5 Console.Readkey() End Sub End Module Result:

12 Pemrograman VisualMinggu …5… Page 11 Using Exit in Repetition Statement The Exit Do Statement can be executed in a Do While…Loop, Do…Loop While, Do Until…Loop or Do…loop until statement, to cause the program to exit immediately from that repetition statement. The Exit For and Exit While statements cause immediate exit from For…Next and while …End While Loops, respectively

13 Pemrograman VisualMinggu …5… Page 12 Using the Exit Keyword in a Repetition Structure Exit For Exit Do Exit While Example: Module Module1 Sub Main() Dim counter As Integer = 1 Do Console.Write(counter & " ") counter += 1 If counter=3 Then exit do End If Loop While counter <= 5 Console.Readkey() End Sub End Module

14 Pemrograman VisualMinggu …5… Page 13 Logical Operators AndAlso expr1expr2Result FalseFalseFalse FalseTrueFalse TrueFalseFalse TrueTrueTrue OrElse expr1expr2Result FalseFalseFalse FalseTrueTrue TrueFalseTrue TrueTrueTrue

15 Pemrograman VisualMinggu …5… Page 14 Example of AndAlso & OrElse If age >=15 AndAlso age <= 40 Then Console.Write(“Usia Produktif”) Else Exit Do End If

16 Pemrograman VisualMinggu …5… Page 15 Questions & Answers

17 Pemrograman VisualMinggu …5… Page 16 Thank You


Download ppt "Pemrograman VisualMinggu …5… Page 1 MINGGU Ke Lima Pemrograman Visual Pokok Bahasan: Control Statement II Tujuan Instruksional Khusus: Mahasiswa dapat."

Similar presentations


Ads by Google