This document contains lecture slides for CSE110 Principles of Programming with Java. It discusses loops and conditional statements like break, continue, and nested loops. It then presents a case study on implementing Tic Tac Toe in Java, with pseudocode showing how to initialize the game board, take user and computer moves, check for a winner or tie, and reprint the board. The slides are attributed to instructor Javier Gonzalez-Sanchez and provide his contact information.
1. CSE110
Principles of Programming
with Java
Lecture 13:
Loops and Conditional statements
Javier Gonzalez-Sanchez
javiergs@asu.edu
javiergs.engineering.asu.edu
Office Hours: By appointment
2. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 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;
}
}
3. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 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");
}
4. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 4
Nested loops
• We can have a loop inside of another loop
for (int i=1; i<=3; i=i+1) {
for (int j=4; j>=1; j=j-1) {
System.out.println(i + "," + j);
}
}
5. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 5
One more thing
• We can have a loop inside of another loop
for (int i=1; i<=3; i++) {
for (int j=4; j>=1; j--) {
System.out.println(i + "," + j);
}
}
16. CSE110 - Principles of Programming
Javier Gonzalez-Sanchez
javiergs@asu.edu
Summer 2017
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.