1 / 15

Controlling Program Flow With Decision Structures

Controlling Program Flow With Decision Structures. The If…Then Statement. Decision structures to control flow True/False (boolean) decision structure If a condition is true then certain statements will operate If intGuess = 7 Then Me.lblMessage.Text = “You guessed it” End If.

yael-perry
Download Presentation

Controlling Program Flow With Decision Structures

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. Controlling Program FlowWith Decision Structures

  2. The If…Then Statement • Decision structures to control flow • True/False (boolean) decision structure • If a condition is true then certain statements will operate • If intGuess = 7 Then • Me.lblMessage.Text = “You guessed it” End If

  3. The If…Then Statement • Many If…Then statements will use relational operators • = • < • < = • > • > = • < >

  4. The If…Then…Else Statement • Else clause: evaluated when the If condition evaluates to false. • If intX = intSecret Then • Me.lblMessage.Text = “You Guessed it” Else Me.lblMessage.Text = “Try Again.” End If

  5. Nested If…Then…Else Statements • When you have an If…Then decision structure within an If…Then decision structure

  6. If…Then…ElseIf Statement • Used to decide between three or more actions

  7. Select…Case Statement • Another decision structure • Sometimes preferred over the if…then…elseif

  8. Select…Case Is Statement • Compares a range of values by using relational operators.

  9. Random Numbers • Rnd generates random numbers • Equal to or greater than 0, less than 1 • (High – Low +1) * Rnd () + Low • Eliminate everything after the decimal Int • Randomize

  10. Static Variables • Retains the value of a variable throughout program execution • Keep the scope as narrow as possible • Static intSecret As Integer

  11. Algorithms • An algorithm states the code in words • Determine a secret number • Get a number from the player • Compare the number and the secret # • If higher than… • If lower than… • If equal… • Pseudocode: an algorithm with some code

  12. Logical Operators • Joins two boolean expressions • Not, And, Or (order of operation) • If intGrade < 0 Or intGrade > 100 then • ‘out of range • If strItem = “book” And intquant > 10 then • ‘discount items over 10 • If Not strItem = “book” then • ‘done for every item except book me.radrock.checked

  13. Message Box • Dialog box • Created by using its own statement MessageBox.Show(“display”, “title bar”) • Place anywhere you want a messagebox to appear

  14. Counter Variables • A variable that is incremented by a constant number • Keeps track of number of guesses, button clicks, lives in a game • To increment a counter it is the counter = counter + constant intNumTries = intNumTries + 1 Test Grade

  15. Checkbox Control • Prefix - chk • Similar to radio buttons • More than one may be selected • .checked property To do Menu

More Related