FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println(); for (int.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Type Title Here for Tic-Tac-Toe Type names of students in group here.
Mock test review Revision of Activity Diagrams for Loops,
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University.
Nested For Loops It is also possible to place a for loop inside another for loop. int rows, columns; for (rows=1; rows
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Loops Chapter 4. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while” structures.
LAB 10.
Unit 2: Java Introduction to Programming 2.1 Initial Example.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/30/2012 and 10/31/2012 -Code PrintCalendar.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Answers to Assignment #1 (Assignment due: Wed. Feb. 05, 2003) 1. What does the "plateform independence" mean? How is it implemented in Java? 2. Summarize.
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
Building Java Programs Parameters and Objects. 2 Redundant recipes Recipe for baking 20 cookies: –Mix the following ingredients in a bowl: 4 cups flour.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
Printing with for Loops To print a character multiple times, use a for loop. for (int j = 1; j
SELF STUDY. IF STATEMENTS SELECTION STRUCTURE if selection statement if … else selection statement switch selection statement.
Application development with Java Lecture 6 Rina Zviel-Girshin.
Computer Programming with Java Chapter 2 Primitive Types, Assignment, and Expressions.
Example 1 Writing Powers Write the product as a power and describe it in words. a. 44= to the second power, or 4 squared 9 to the third power,
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
CS001 Introduction to Programming Day 6 Sujana Jyothi
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
WAP to find out the number is prime or not Import java.util.*; Class Prime { public static void main(string args[]) { int n,I,res; boolean flag=true;
CS 112 Introduction to Programming Loop Examples; Variable Scoping; Nested Loops; Yang (Richard) Yang Computer Science Department Yale University 208A.
Fractions Part Two. How many halves are in a whole? 2 1/2.
Lesson 7 Iteration Structures. Iteration is the third control structure we will explore. Iteration simply means to do something repeatedly. All iteration.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
補充教材. 主題 JDK 與 Tomcat 5.5.x 的安裝 迴圈 MySQL Workbench.
Staples are our staple Building upon our solution.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class.
Chapter 9 Repetition.
Building Java Programs
A Java Program: // Fig. 2.1: Welcome1.java // Text-printing program.
Exercise Java programming
BIT 115: Introduction To Programming
using System; namespace Demo01 { class Program
Zoom In Game.
Sum of natural numbers class SumOfNaturalNumbers {
Which fraction does correspond to the coloured part?
TK1114 Computer Programming
Decision statements. - They can use logic to arrive at desired results
יסודות מדעי המחשב – תרגול 4
Computing Adjusted Quiz Total Score
The for-loop and Nested loops
Adapted from slides by Marty Stepp, Stuart Reges & Allison Obourn.
Chapter 9 Control Structures.
Student #7 starts with Locker 7 and changes every seventh door
Recursive GCD Demo public class Euclid {
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
Scope of variables class scopeofvars {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
CIS 110: Introduction to Computer Programming
Which fraction does correspond to the coloured part?
MATH 1310 Section 4.1.
The Solar System.
Consider the following code:
MATH 1310 Section 4.1.
MATH 1310 Section 4.1.
Presentation transcript:

FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println(); for (int j = 1; j <= i; j++) { System.out.print("*"); } } } }

public class NestedFor // FIRST TIME THROUGH THE LOOP { public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println(); for (int j = 1; j <= i; j++) { System.out.print("*"); } } } } i = 1 1 is less than or equal to 7 j = 1 1 is less than or equal to 1 Print *, increment, and loop 2 is NOT equal to 1 so fall out and return to outer for New line *

public class NestedFor // SECOND TIME THROUGH THE LOOP { public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println(); for (int j = 1; j <= i; j++) { System.out.print("*"); } } } } i = 2 2 is less than or equal to 7 j = 1 1 is less than or equal to 2 Print *, increment, and loop 2 is less than or equal to 2 Print *, increment, and loop 3 is NOT equal to 2, so fall out and return to outer for New line * 03 **

public class NestedFor // THIRD TIME THROUGH THE LOOP { public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println(); for (int j = 1; j <= i; j++) { System.out.print("*"); } } } } i = 3 3 is less than or equal to 7 j = 1 1 is less than or equal to 3 Print *, increment, and loop 2 is less than or equal to 3 Print *, increment, and loop 3 is less than or equal to 3 Print *, increment, and loop 4 is NOT equal to 3, so fall out and return to outer for New line * 03 ** 04 ***

public class NestedFor // FOURTH TIME THROUGH THE LOOP { public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println(); for (int j = 1; j <= i; j++) { System.out.print("*"); } } } } i = 4 4 is less than or equal to 7 j = 1 1 is less than or equal to 4 Print *, increment, and loop 2 is less than or equal to 4 Print *, increment, and loop 3 is less than or equal to 4 Print *, increment, and loop 4 is less than or equal to 4 Print *, increment, and loop 5 is NOT equal to 4, so fall out and return to outer for New line * 03 ** 04 *** 05 ****

public class NestedFor // FIFTH TIME THROUGH THE LOOP { public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println(); for (int j = 1; j <= i; j++) { System.out.print("*"); } } } } i = 5 5 is less than or equal to 7 j = 1 1 is less than or equal to 5 Print *, increment, and loop 2 is less than or equal to 5 Print *, increment, and loop 3 is less than or equal to 5 Print *, increment, and loop 4 is less than or equal to 5 Print *, increment, and loop 5 is less than or equal to 5 Print *, increment, and loop 6 is NOT equal to 5, so fall out and return to outer for New line * 03 ** 04 *** 05 **** 06 *****

public class NestedFor // SIXTH TIME THROUGH THE LOOP { public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println(); for (int j = 1; j <= i; j++) { System.out.print("*"); } } } } i = 6 6 is less than or equal to 7 j = 1 1 is less than or equal to 6 Print *, increment, and loop 2 is less than or equal to 6 Print *, increment, and loop 3 is less than or equal to 6 Print *, increment, and loop 4 is less than or equal to 6 Print *, increment, and loop 5 is less than or equal to 6 Print *, increment, and loop 6 is less than or equal to 6 Print *, increment, and loop 7 is NOT equal to 6, so fall out and return to outer for New line * 03 ** 04 *** 05 **** 06 ***** 07 ******

public class NestedFor // SEVENTH TIME THROUGH LOOP { public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println(); for (int j = 1; j <= i; j++) { System.out.print("*"); } } } } i = 7 7 is less than or equal to 7 j = 1 1 is less than or equal to 7 Print *, increment, and loop 2 is less than or equal to 7 Print *, increment, and loop 3 is less than or equal to 7 Print *, increment, and loop 4 is less than or equal to 7 Print *, increment, and loop 5 is less than or equal to 7 Print *, increment, and loop 6 is less than or equal to 7 Print *, increment, and loop 7 is less than or equal to 7 Print *, increment, and loop 8 is NOT equal to 7, so fall out and return to outer for New line * 03 ** 04 *** 05 **** 06 ***** 07 ****** 08 *******

public class NestedFor // EIGHTH TIME THROUGH LOOP { public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println(); for (int j = 1; j <= i; j++) { System.out.print("*"); } } } } i = 8 8 is NOT less than 7 Break from for loop * 03 ** 04 *** 05 **** 06 ***** 07 ****** 08 ******* 8