CSE110 Principles of Programming with Java Lecture 14: Loops and Conditional statements Javier Gonzalez-Sanchez [email protected] javiergs.engineering.asu.edu | javiergs.com Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 2 break Statement We can use a break statement to get out of the loop for (int i=1; i<=100; i=i+2) { System.out.println(i); if (i % 15 == 0) { break; } }
Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 3 continue Statement • After executing a continue statement, the rest of the statements within the loop will be skipped, then the loop condition will be evaluated again. for (int i=1; i<=4; i+=1) { System.out.println(i); System.out.println("Before"); if (i % 2 == 0) { continue; } System.out.println("After"); }
CSE110 - Principles of Programming Javier Gonzalez-Sanchez [email protected] Summer 2020 Disclaimer. These slides can only be used as study material for the class CSE110 at ASU. They cannot be distributed or used for another purpose.