1 / 29

Only process if you get a yes to the condition. Can drop out without processing.

Understand the logic of a do-while loop with conditions checked inside, essential for proper programming; check the pseudocode and flowchart for clarity.

autumnc
Download Presentation

Only process if you get a yes to the condition. Can drop out without processing.

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. Only process if you get a yes to the condition. Can drop out without processing.

  2. Will always process once since I check after processing.

  3. Note the accompanying pseudocode that shows the logic in English. The process to be done in the loop is between the do while with its condition and the end while loop. The condition to determine whether to do the loop or not is expressed in the do while statement.

  4. Again note the pseudocode and the do while loop with the condition as part of the statement.

  5. Note in the pseudocode the condition is in the until at the end of the loop because I process before I check.

  6. Again, look at the flowchart and the pseudocode and note that the condition is checked in the do and therefore I may never enter the loop.

  7. Again, in the pseudocode and the flowchart the condition is checked after I process once. In the pseudocode that means I check in the until.

  8. This shows why it is an assignment sign. ct is not equal to ct + 1 but I can assign the results of adding 1 to ct to the memory variable ct.

  9. The if ends with an end if in both the flowchart and the pseudocode. In the flowchart the end of the if is done with the small circle.

  10. The no to the question results in using an ELSE in the pseudocode and showing the processing to do if it is not true in the else. The END IF ends the entire if.

  11. In pseduocode I am using a Move "OKAY" to msg. I could have used an assignment sign and assigned "OKAY" to msg.

  12. In this example I have nothing to do unless both conditions get a yes so I can make this a compound using the AND.

  13. I indent pseudocode for clarity.

  14. It the first condition is true, I drop to the second condtion. It that is true I process by moving OKAY else I process by moving PROBLEM. Then I end the second condition. SInce I have nothing to do if the first condition is not true, I then reach the end if for the first condition.

  15. Can't make a compound because the NOs on the conditions require different processing.

  16. Since I want to do the same processing if either condition is true this is an OR with 2 chances.

  17. I have the same processing if either is true, so I can make a compound.

  18. If I get a NO to both conditions, then I move PROBLEM to message.

  19. I want to process the YESs to the two conditions differently so it cannot be a compound.

  20. I this example, invcd has to be an A and then either of the other two conditions has to be true.

  21. Alternate way to code. I ask the condition that has to be true separately.

More Related