1 / 25

REPETITION (IN EVERYDAY LIFE)

REPETITION (IN EVERYDAY LIFE). CONTROL STRUCTURES. OBJECTIVES. To FULLY understand the following control structures: REPEPITION SELECTION (To be covered in another set of slices.) SEQUENCE (To be covered in another set of slices.)

benedetto
Download Presentation

REPETITION (IN EVERYDAY LIFE)

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. REPETITION(IN EVERYDAY LIFE)

  2. CONTROL STRUCTURES OBJECTIVES • To FULLY understand the following control structures: • REPEPITION • SELECTION (To be covered in another set of slices.) • SEQUENCE (To be covered in another set of slices.) • To see how control structures are used every second in our daily lives. • To understand that a FULL comprehension of these control structures is the KEY to problem solving when writing computer programs. • IMPORTANT: You MUST learn these control structures PERFECTLY in order to succeed in this course. These are the most important concepts the course.

  3. CONTROL STRUCTURES • Three Control Structures: • 1. Repetition (Also called Iteration or Looping) • DO-WHILE • DO-UNTIL • 2. Selection (Also called Decision) • IF-THEN-ELSE • CASE • 3. Sequence IMPORTANT: You MUST learn these control structures PERFECTLY in order to succeed in this course. You can't solve computer programming problems without control structures. These are the most important concepts the course. Do this throughout the course.

  4. REPETITION (DOWHILE) IN EVERYDAY LIFE • Everyday Life: • Every second, we are engaged in one or more control structures. • DOWHILE • DO something WHILE a certain condition is TRUE. • All MIS 15 students MUST identify 25 situations where they are using the DOWHILE control structure in their everyday life before the next class. Do this throughout the course. DOWHILE examples We listen WHILE the boss is talking. I rest WHILE I am sick. I sleep WHILE I am tired. I smile WHILE I am happy. I yell WHILE I am mad.

  5. REPETITION (DOWHILE) IN EVERYDAY LIFE • DOWHILE CONTROL STRUCTURE • DO the loop WHILE the condition is TRUE. • With pretest: • Condition is tested BEFORE the body of the loop is executed. • With posttest: • Condition is tested AFTER the body of the loop is executed. • The red symbols and lines make up the D0WHILE control structure below. • In Visual Basic.NET there is a loop called DOWHILE and it functions exactly as this one.. WHILE time is less than 5:00 pm, continue working. Condition Pretest DOWHILE Loop Body of the Loop

  6. REPETITION (DOUNTIL) IN EVERYDAY LIFE • Everyday Life: • Every second, we are engaged in one or more control structures. • DOUNTIL • DO something UNTIL a certain condition is TRUE. • All MIS 15 students MUST identify 25 situations where they are using the DOUNTIL control structure in their everyday before the next class. DOUNTIL examples We listen UNTIL the boss is silent. I rest UNTIL I am well. I sleep UNTIL I am rested. I smile UNTIL I am sad. I yell UNTIL I am calm.

  7. REPETITION (DOUNTIL) IN EVERYDAY LIFE More DOUNTIL examples I work UNTIL the house is finished. I cook UNTIL the food is done I work UNTIL 5:00 pm

  8. REPETITION (DOUNTIL) IN EVERYDAY LIFE • DOUNTIL CONTROL STRUCTURE • DO the loop UNTIL the condition is TRUE. • With pretest: • Condition is tested BEFORE the body of the loop is executed. • With posttest: • Condition is tested AFTER the body of the loop is executed. • The red symbols and lines make up the D0UNTIL control structure below. • In Visual Basic.NET there is a loop called DOUNTIL and it functions exactly as this one.. I work UNTIL 5:00 pm Condition Pretest DOUNTIL Loop Body of the Loop

  9. REPETITION (DOWHILE vs. DOUNTIL) Figs_1-140 • DIFFERENCE BETWEEN DOWHILE AND DOUNTIL • DOWHILE: DO the body of the loop WHILE the condition is TRUE. • If the condition is TRUE, the body of the loop is executed. • DOUNTIL: DO the body of the loop UNTIL the condition is TRUE. • If the condition is FALSE, the body of the loop is executed. DOWHILE DOUNTIL Major Difference TRUE FALSE FALSE TRUE

  10. REPETITION (Pretest vs. Posttest) Figs_1-140/1-150 • DIFFERENCE BETWEEN DOWHILE PRETESTAND POSTEST • PRETEST: The BODY of the loop is executed AFTER the condition is checked. • POSTTEST: The BODY of the loop is executed BEFORE the condition is checked. • IMPORTANT: The Posttest GUARANTEES that the body of the loop will be executed at least ONCE. DOWHILE (with Pretest) DOWHILE (with Posttest) Major Difference Pretest (Before) TRUE TRUE FALSE Posttest (After) FALSE

  11. REPETITION (Pretest vs. Posttest) Figs_1-140/1-150 • DOWHILE CONDITION IS TRUE WITH PRETEST • PRETEST: The BODY of the loop is executed AFTER the condition is checked. DOWHILE (with Pretest) I check my gas gauge (Condition) before I start driving (Body of Loop). Condition (Pretest) TRUE DOWHILE (with Pretest) FALSE Body of loop.

  12. REPETITION (Pretest vs. Posttest) Figs_1-140/1-150 • DOWHILE CONDITION IS TRUE WITH POSTTEST • POSTTEST: The BODY of the loop is executed AFTER the condition is checked. DOWHILE (with Posttest) I check my gas gauge (Condition) after I start driving (Body of Loop). Body of loop. Condition (Posttest) TRUE DOWHILE (with Posttest) FALSE

  13. FOUR REPETITION LOOPS DOUNTIL condition is TRUE DOWHILE condition is TRUE TRUE TRUE TRUE TRUE

  14. SOLVE ANY PROBLEM WITH THESE TWO LOOPS These are the two most common loop variations. Learn them well. DOUNTIL condition is TRUE DOWHILE condition is TRUE TRUE Pretest Posttest TRUE

  15. APPENDEX (FLOWCHART SYMBOLS USED IN THIS COURSE) Terminal Input/Output Process Predefined Process Decision Preparation Terminal symbol - This symbol indicates the starting or stopping point in the logic. Every flowchart should begin and end with a terminal symbol. Input/Output symbol - This symbol represents an input or output process in an algorithm, such as reading input or writing output. Process symbol - Represents any single process in an algorithm, such as assigning a value or performing a calculation. The flow of control is sequential. Predefined process symbol - Represents a module in an algorithm; that is, a predefined process that has its own flowchart, and code. Decision symbol - Represent a decision in the logic involving the comparison of two values. Alternative paths are followed depending on whether the decision symbol is true or false. Preparation symbol - In this course, use it for initializing loops.

  16. APPENDEX (FLOWCHART SYMBOLS USED IN THIS COURSE) Flowlines - Connects various symbols in a flowchart, and contain an arrowhead. Use arrowhead when needed for clarity.

  17. Repitition – Loops • OBJECTIVES: • To understand “For Loops” • To understand “Do Loops” • To apply DoWhile and DoUntil Control Structure logic to “For Loops” and “Do Loops”.

  18. For Loops For Loop – GENERAL FORMAT For LoopCounter = InitialValue To TerminalValue ‘Program statement(s) Next LoopCounter You can use variables here. This control structure logic is Do While the condition is True with a Pretest CODE EXAMPLE: Dim I As Integer For I = 1 To 5 lblDisplay.Text = CStr(I) Next I RESULT: 1 2 3 4 5

  19. For Loops (Nested Loops) For Loop – GENERAL FORMAT For LoopCounter = InitialValue To TerminalValue ‘Program statement(s) Next LoopCounter You can use variables here. These control structures’ logic is Do While the condition is True with a Pretest CODE EXAMPLE (Nested Loops): Dim I As Integer Dim J As Integer For J = 1 to 2 For I = 1 To 5 lblDisplay.Text = CStr(I) Next I lblDisplay.Text = CStr(J) Next J RESULT: 1 2 3 4 5 1 1 2 3 4 5 2

  20. For Loops For Loop with Step – GENERAL FORMAT For LoopCounter = InitialValue To TerminalValue Step StepValue ‘Program statement(s) Next LoopCounter You can use variables here. This control structure logic is Do While the condition is True with a Pretest CODE EXAMPLE: Dim I As Integer For I = 1 To 5 Step 3 lblDisplay.Text = CStr(I) Next I RESULT: 1 4 Note: If “Step” is not used, the default Step is + 1.

  21. For Loops For Loop with Step – GENERAL FORMAT For LoopCounter = InitialValue To TerminalValue Step StepValue ‘Program statement(s) Next LoopCounter You can use variables here. This control structure logic is Do While the condition is True with a Pretest CODE EXAMPLE: Dim I As Integer For I = 5 To 1 Step - 1 lblDisplay.Text = CStr(I) Next I RESULT: 5 4 3 2 1

  22. Do Loops Do Loop – GENERAL FORMAT Do While (Condition) ‘Program statement(s) Loop This control structure logic is Do While the condition is True with a Pretest You can use a variable here. CODE EXAMPLE: Dim I As Integer I = 1 Do While I <= 5 lblDisplay.Text = CStr(I) I = I + 1 Loop RESULT: 1 2 3 4 5

  23. Do Loops Do Loop – GENERAL FORMAT Do ‘Program statement(s) Loop Until (Condition) This control structure logic is Do Until the condition is True with a Posttest. CODE EXAMPLE: Dim I As Integer I = 0 Do lblDisplay.Text = CStr(I) I = I + 1 Loop Until (I = 5) RESULT: 1 2 3 4 5 Note: A Do Until control structure with a Posttest guarantees that the loop body will always be executed at least once. You can use a variable here.

  24. You must know the previous loop slides extremely well.These loops are fundamental to problem solving in programming.With these fundamental loop structures, you can solve any algorithm requiring repetition.

  25. REPETITION IN EVERYDAY LIFE

More Related