Pages Section: Control2: Repetition

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Program Looping EE2372 Software Design I Dr. Gerardo Rosiles.
While loops.
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
LOOP / REPETITION while loop. for loop do/while loop We assume that loops are not meant to be infinite. That is, there should always be a way out of the.
Repetition Chapter 4: Control structures. Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Loop Statements After reading and studying this Section,
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Branching Constructs Review l what are branching constructs? what type of branching constructs have we studied? l what is nested if? l what is multiway.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
Chapter 5: Control Structures II (Repetition)
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
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.
Chapter 4: Control Structures II
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
Chapter 5 Control Structure (Repetition). Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
Chapter 5 Loops. Overview u Loop Statement Syntax  Loop Statement Structure: while, for, do-while u Count-Controlled Loops u Nested Loops u Loop Testing.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
CHAPTER 3 CONTROL STRUCTURES ( REPETITION ) I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
CSI 3125, Preliminaries, page 1 Control Statements.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Topic 4: Looping Statements
Chapter 4 Repetition Statements (loops)
Branching Constructs Review
Control Structures II (Repetition)
CiS 260: App Dev I Chapter 4: Control Structures II.
Chapter 2.2 Control Structures (Iteration)
Programming Fundamentals
Bools & Ifs.
Control Structures.
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Chapter 6 Repetition Objectives ❏ To understand basic loop concepts:
Conditinoal Constructs Review
Loop Control Structure.
For & do/while Loops.
For Net Art Lecture 2 J Parker
Conditinoal Constructs Review
Pages Section: Control2: Repetition
Pages:51-59 Section: Control1 : decisions
Repetition Control Structure
Chapter 8: More on the Repetition Structure
Chapter 2.2 Control Structures (Iteration)
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
CS149D Elements of Computer Science
Introduction to Computer Science
Loops & Nested Loops CSE 120 Winter 2019
PROGRAM FLOWCHART Iteration Statements.
Statements in C Programming
Pages:51-59 Section: Control1 : decisions
Repetition Structures
Pages Section: Control2: Repetition
LOOP Basics.
Presentation transcript:

Pages 61-68 Section: Control2: Repetition

Introduction Three major types of language constructs or statements: Sequential statement Decision/selection statement Repetition/iteration statement Iterative statements Are used to compact length lines of repetitive code Expresses concisely a repetitive operation We will learn “for” statement of Processing

Examples line(20, 20, 20, 180); line(30, 20, 30, 180); line(40, 20, 40, 180); line(50, 20, 50, 180); line(60, 20, 60, 180); line(70, 20, 70, 180); line(80, 20, 80, 180); line(90, 20, 90, 180); line(100, 20, 100, 180); for (i = 20; i< 120; i= i+ 10) { line(i,20,i,180); }

For syntax and semantics for (init; test; update) { statements } The init statement is executed The test is evaluated to true or false If the test is true, execute the statement within the block indicated by { } If the test is false skip to the statement after the “for” statement

More examples for (int x = -16; x <100; x = x + 10) { line(x,0,x+15, 50); } strokeWeight(4); for (int x = -8; x , 100; x = x + 10) { line (x,50,x+15, 100); }

More Examples noFill(); for (int d = 150; d > 0; d = d -10) { ellipse (50, 50, d, d); } Try some of the examples in page 64

Nested Iteration A “for” statement produces repetition in one dimension. Nesting a “for” within a “for” generates “looping” in 2 dimensions. Lets look at some examples.

Nested Loops strokeWeight(4); for (int y = 10; y <100; y = y+10) // dimension y point(10,y); for (int x = 10; x <100; x = x+10) // dimensión x point(x,10); //nested for .. Two dimensions point(x,y);

More Examples noStroke(); for (int y = 10; y <100; y = y+10) // dimension y for (int x = 10; x <100; x = x+10) // dimensión x { fill((x+y)*1.4); rect(x,y,10,10); }

Summary We studied the syntax, semantics and purpose of “for” statement We also looked at many examples Make sure you format the statements for readability, esp. now that we are adding complex statements to your code.