Decision Structure

download Decision Structure

of 21

Transcript of Decision Structure

  • 7/28/2019 Decision Structure

    1/21

    IfThen

    Select Case

  • 7/28/2019 Decision Structure

    2/21

    Comparison Operator Meaning= Equal to

    Not equal to

    > Greater than

    < Less than>= Greater than or equal to

  • 7/28/2019 Decision Structure

    3/21

    Conditional Expression Result10 20 True (10 is nor equal to 20)

    Score < 20 True if Score is less than 20;otherwise, False

    Score = Label1.Text True if the Text property of the

    label1 object contains the samevalue as the Score variable;otherwise, False

    TextBox1.Text = Bill True if the word Bill is in the firstext box; otherwise, False

  • 7/28/2019 Decision Structure

    4/21

    To evaluate a condition in the program andtake a course of action based on the result. IfconditionThenstatement

    condition = conditional expression

    statement = a valid VB program statement IfScore >= 20ThenLabelText1.Text = You Win!

    this sort of comparison always result in True

    or False, never result in maybe

  • 7/28/2019 Decision Structure

    5/21

  • 7/28/2019 Decision Structure

    6/21

    LogicalOperator MeaningAnd If both conditional

    expression is True, then theresult is True

    Or If either conditionalexpression is True, then theresult is True

    Not If the conditional expressionis False, then the result isTrue. If the conditional

    expression is True, then theresult is False.

    Xor(exclusive Or)

    If one and only one of theconditional expressions isTrue, then the result is True.If both are True or both are

    False, then the result isFalse.

    Logical Operator ResultVehicle = Bike And Price 10

    n = x + 1

    No

    exit

  • 7/28/2019 Decision Structure

    13/21

    Chr(13) --> move to the beginning oflineChr(10) --> move to the next line

  • 7/28/2019 Decision Structure

    14/21

  • 7/28/2019 Decision Structure

    15/21

    Private Sub Command1_Click()Dim strName As String

    strName = UCase(Text1.Text)

    For i = 1 To 5

    FontSize = 10 + iIf strName = keluar" Then Exit For

    Print strName; " "; i

    Next i

    End Sub

  • 7/28/2019 Decision Structure

    16/21

    PSP 1

    PSP2

    PSP3

    PSP 4

    PSP 5

  • 7/28/2019 Decision Structure

    17/21

    Alternative toForNext loops

    Execute a group ofstatement until acertain condition is

    True Syntax :

    Do whileconditionblock of statements tobe executed

    Loop

    Eg1:Dim InpName As StringDo While InpName DoneInpName = InputBox(Enter your name

    or typeDone to quit)

    IfInpName Done ThenTextBox1.Text = InpName

    Loop Eg2:Dim InpName As StringDo

    InpName = InputBox(Enter your nameor typeDone to quit)

    IfInpName Done ThenTextBox1.Text = InpName

    Loop While InpName Done

  • 7/28/2019 Decision Structure

    18/21

    It is important to design your test conditionso that each loop has a true exit point.

    Example:Dim Number As Double

    Do

    Number = InputBox(Enter a number to square. Type -1to quit)

    Number = Number * Number

    TextBox1.Text = NumberLoop While Number >= 0

  • 7/28/2019 Decision Structure

    19/21

  • 7/28/2019 Decision Structure

    20/21

    BREAK

  • 7/28/2019 Decision Structure

    21/21

    Rata-rata kita menuturkan 5000 perkataan setiap hari (walaupun 80% kita hanya

    bercakap pada diri sendiri

    Jika anda terbersin terlalu kuat, anda dapat meretakkan tulang rusuk. Jika andacuba menahan bersin, anda boleh menyebabkan pembuluh darah di kepala dan

    leher pecah, dan menyebabkan kematian. Jika memaksa mata terbuka waktu

    Bersin bola mata boleh terkeluar dari tempantnya

    Kita menyambut ulang tahun bersama 9 juta orang dari seluruh dunia

    Kutu rambut sebenarnya lebih suka hidup di kulit kepala yang bersih daripada

    yang kotor

    Orang yang menggunakan tangan kanan, kira-kira, 9 tahun lebih panjang umur

    dari orang kidal

    Vitamin pada buah biasanya terdapat pada kulitnya