New Tools And Workshop Mod & For Loops. Modulo Calculates the remainder (remember long division?) % Examples: 7 % 3 10 % 2 2 % 3 evaluates to 1 evaluates.

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

 Demonstrate use of a “for loop” in the design and development of a Java program to calculate the total of a one-dimensional array of 6 integers.  Design.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
CS150 Introduction to Computer Science 1
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Lecture 6: for Loops Yoni Fridman 7/6/01 7/6/01. OutlineOutline  The for statement  The for statement’s format  The for statement’s flow  Comparing.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
Repetition Structures: For Loop Constants CSC 1401: Introduction to Programming with Java Week 5 Wanda M. Kunkle.
Looping Yong Choi School of Business CSU, Bakersfield.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
TODAY’S LECTURE Review Chapter 2 Go over exercises.
1 for Loops Computer Science is a science of abstraction - creating the right model for a problem and devising the appropriate mechanizable techniques.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
Arrays After a while. Remember for loops? for(int i = 0; i < 10; i++){ System.out.println(i); } -But what if we are unsure of how many cycles we need?
Copyright 2009 by Pearson Education Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos: Ch.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
REPETITION CITS1001. Scope of this lecture Repetition for loops while loops 2.
Chapter 4: Loops and Files
Using Shortcut Arithmetic Operators Accumulator: A variable that is used to total. Its value is repeatedly increased by some amount. Java provides shortcuts.
CIS 234: LOOPS Adapted from materials by Dr. Donald Bell, 2000 (updated April 2007)
Loops ISYS 350. A Box of Chocolate Repeat this process until box is empty: – Take one chocolate from the box – Eat the chocolate – Box has more chocolate?
Loops ISYS 350. Compute the sum of a list of numbers: Example: 5, 2, 10, 8, 4 Process: Sum= 0 Get a number from the list Sum = Sum + the number Repeat.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
1 The for loop. 2 Repetition with for loops So far, repeating a statement is redundant: System.out.println("Homer says:"); System.out.println("I am so.
ADMIT TICKET WHAT DOES THIS OUTPUT? double y = 2.5; int x = 6 / (int) y; System.out.println(“x = “ + x);
February ,  2/16: Exam 1 Makeup Papers Available  2/20: Exam 2 Review Sheet Available in Lecture  2/27: Lab 2 due by 11:59:59pm  3/2:
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos:
Repetition 8/9/2009. Learning to Program -- Suggestions Spend a lot of time fiddling around with code –Programming is something you have to learn by doing.
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson All rights reserved.
For Loop Tips And Tricks
Loops ISYS 350. Two Types of Loops while loop for loop.
Chapter 9 Control Structures.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING While Loop.
CS0007: Introduction to Computer Programming The for Loop, Accumulator Variables, Seninel Values, and The Random Class.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Loops ISYS 350. Two Types of Loops while loop for loop.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
Inside Class Methods Chapter 4. 4 What are variables? Variables store values within methods and may change value as the method processes data.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
ECE122 Feb 10, Unary Operator An operator that takes only a single operand Plus: + Minus: – Cast: (type). E.g. (double)
Loops ISYS 350. Two Types of Loops while loop for loop.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Slides by Evan Gallagher
Slides by Evan Gallagher
CHAPTER 4 DECISIONS & LOOPS
Chapter 9 Repetition.
Lecture 4b Repeating With Loops
Loop Structures.
Primitive Data, Variables, Loops (Maybe)
Review If you want to display a floating-point number in a particular format use The DecimalFormat Class printf A loop is… a control structure that causes.
User input We’ve seen how to use the standard output buffer
Counted Loops.
Chapter 5 Repetition.
LRobot Game.
Chapter 9 Control Structures.
Lecture Notes – Week 3 Lecture-2
© A+ Computer Science - What is a LOOP? © A+ Computer Science -
Lab5 PROGRAMMING 1 Loop chapter4.
Building Java Programs
Code Refresher Test #1 Topics:
February , 2009 CSE 113 B.
Seating “chart” Front - Screen rows Back DOOR.
PROGRAM FLOWCHART Iteration Statements.
Building Java Programs
Presentation transcript:

New Tools And Workshop Mod & For Loops

Modulo Calculates the remainder (remember long division?) % Examples: 7 % 3 10 % 2 2 % 3 evaluates to 1 evaluates to 0 evaluates to 2

Incrementing and Decrementing Often you want to increase or decrease an int value by 1 We’ve done it like this: int i = 5; i = i + 1;// now i has a value of 6 Java has a shortcut: int y = 5; y++;// now i has a value of 6 y--;// now i has a value of 5

For loops Often you want to repeatedly execute a piece of code Many uses Example: for(int i = 0; i < 10; i++){ System.out.println(i); } New Keyword! Parenthesis encompass the 3 conditions Curly braces encompass the code to be looped over

3 conditions of a for loop for(int i = 0; i < 10; i++){ System.out.println(i); } 1.declare and define a counter variable 2. boolean condition, checked every iteration 3. update counter variable every iteration

Let’s do some coding…