Presentation is loading. Please wait.

Presentation is loading. Please wait.

SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder

Similar presentations


Presentation on theme: "SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder"— Presentation transcript:

1 SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
5/21/2019 SE1011 Week 4, Class 2 Today Muddiest Points Finishing GUI loop example Nested Loops Next Half-Exam: Week 5, Monday SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder Dr. Josiah Yoder

2 do-while & nested loops
SE1011 5/21/2019 Muddiest Loop Points I get the whole concept of loops, but not the application of it writing loops What is the difference betwen "while" and "do while" types of loops It sounds like some of the class could use another detailed run-through of nested for loops. nested loops how to get a nested loop to start another line. how to make a loop print out a different value and count stars. for loop notation (semicolon instead of comma) loop syntax do while loops and nested loops do-while & nested loops Dr. Josiah Yoder

3 Muddiest Loop Points Is there an optimal loop? types of loops
SE1011 5/21/2019 Muddiest Loop Points Is there an optimal loop? types of loops you can exit for and come back, but how can you exit if and come back? can if loop How to determine which loop to put first (width or height). nested loops Making the programs impossible to break error handling nested loops (2x) going from loop to loop (variables, scanners, etc.) loop scope? when to use for versus while? how nested loops interact (still fuzzy on the star example) Dr. Josiah Yoder

4 Types of Loops: do-while vs while
Condition checked first May not enter body If condition false first time Body executed first Will enter body at least once SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder

5 Types of Loops: for vs. while
general-purpose loop Use when you don't know how many times loop will execute counting loop Use when you know how many times loop will execute SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder

6 SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
5/21/2019 Why loop at all? To let the computer count To play video or music To recover from user errors To let user repeat a task To search …any time you want to run part of your code more than once! SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder Dr. Josiah Yoder

7 Nested Loops – an example
do print "Times to sing? 0 to exit" input timesToSing timesSung 0 while timesSung < timesToSing print count timesSungtimesSung+1 while times > 0 SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder

8 SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Nested Loop Design The outer loop is the main task The inner loop performs one step of that task You can test the inner loop without the outer loop Just supply variables The outer loop can change the variables that the inner loop sees SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder

9 SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
5/21/2019 Coding practice See slides from last time, and … Today: CodingBat: starOut SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder Dr. Josiah Yoder

10 SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
5/21/2019 Nested Loops Design a program to print out a rectangle of '*' characters with width characters per line and height lines of characters (pseudocode or flowcharts) SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder Dr. Josiah Yoder

11 SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
5/21/2019 SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder Dr. Josiah Yoder

12 SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
5/21/2019 Acknowledgement This course is based on the text Introduction to Programming with Java by Dean & Dean, 2nd Edition SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder Dr. Josiah Yoder


Download ppt "SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder"

Similar presentations


Ads by Google