1 / 13

5.04 Apply Decision Making Structures

5.04 Apply Decision Making Structures. Computer Programming I. Objective/Essential Standard. Essential Standard: 5.00- Apply Programming and Conditional Logic Indicator: 5.04 Apply decision-making structures. (3%). What is a decision?.

navarro
Download Presentation

5.04 Apply Decision Making 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. 5.04 Apply Decision Making Structures Computer Programming I

  2. Objective/Essential Standard • Essential Standard: 5.00- Apply Programming and Conditional Logic • Indicator: 5.04 Apply decision-making structures. (3%)

  3. What is a decision? • Decisions are made by humans hundreds of times a day. • Computers can make simple decisions also. • What are some decisions you made today so far? Image taken from: learn2bebuddies.com

  4. Boolean Logic • Remember, from the previous section Boolean logic? (Ex: intNum = 5) • Computers use it to make decisions! • There are only two answers: TRUE or FALSE • Computers do not know about Maybe!

  5. The If Decision Structure

  6. Decisions… Decisions • So when you got up this morning what did you do? • This is a decision. Let’s put it in computer terms. • If the sun is out, then I will walk to school Image taken from: http://web.multco.us/sun/linkage

  7. The If…Then Statement If…Then is a decision structure that executes a set of statements only when a condition is true. Form: If condition Then Statements End If T

  8. The If…Then Statement • IF the sun is out (question) THEN I will walk to school. • Remember the computer uses Boolean logic (T/F). So either the sun is out (true) or ANY other state (false). No maybes or in-betweens. • When the question is True, the statements after THEN (and down to ENDIF) execute. They are skipped if the question is False.

  9. The If…Then Statement • Let’s say there was a program that determined whether or not a number was guessed correctly.  Further assume that the ‘correct’ number was 5.  A conditional statement could be set up to notify the user if he/she guessed the correct answer: • In the above code, intGuess=5 represents the condition. The condition is the code statement that needs to be true in order for VB to execute the code between the If and the End If.  • The = sign is called a conditional operator (more on this later).  • Essentially, if the condition is true, the statements between the If and the End If statements are performed; if the condition is false, VB skips those lines and continues on with code that appears after the block of code. 

  10. The If…Then Statement • You will also notice that, when you type the first line of the conditional statement, and press Enter, the next line automatically indents.  • While this doesn’t have any impact on the way the VB reads or executes the code, it serves as an easier way for programmers to read and understand the code structure (other coding structures are indented in this way).  • VB also automatically adds the End If line.  This indentation scheme should always be used with conditional statements.

  11. IF..THEN..ELSE Statement • In Visual Basic we use the IF..THEN..ELSE statement to tell the computer we want it to make a decision. • For exampleIf a = b then c= 10Else c=13End If T F

  12. Use of the ELSE • NOTE: Else is optional- if omitted and the “question” is false no action is taken. • If ELSE is used, the statements after the ELSE will execute if the “question” is NOT true (Boolean FALSE) • If…Then…Else statements are used when the programmer needs to choose between two different outcomes.  For example:

  13. IF..THEN and IF..THEN..ELSE Statements What’s next? In the formative assessment, you will complete a series of steps designed to help you understand the concepts developed in this lesson.  Please follow each step as documented. If you have issues/questions, make sure you watch the videos to gain a better understanding.

More Related