Week 3 - Friday.  What did we talk about last time?  Bitwise practice  Precedence  Control flow.

Slides:



Advertisements
Similar presentations
Flow of Control Chapter 3.
Advertisements

Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Week 4 Kyle Dewey. Overview New office hour location while / do-while / for loops break / continue Termination Exam recap.
Chapter 7 - Iteration. Chapter Goals Program repitiation statements – or loops – with the for, while, and do-while statements Program repitiation statements.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
Chapter 5: Control Structures II (Repetition)
Intro to Java while loops pseudocode. 1 A “Loop” A simple but powerful mechanism for “making lots of things happen!” Performs a statement (or block) over.
Guidelines for working with Microsoft Visual Studio.Net.
Guidelines for working with Microsoft Visual Studio 6.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Flow of Control Loops – Chapter 3.2. Java Loop Statements: Outline the while Statement the do-while Statement the for Statement.
1 Lecture 5  More flow control structures  for  do  continue  break  switch  Structured programming  Common programming errors and tips  Readings:
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Introduction to Computer Programming in c
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
1 CS 177 Week 5 Recitation Slides Loops. 2 Announcements Project 2 due next Thursday at 9PM. Exam 1 this evening (switch and loop not covered) Old exams.
Week 1 - Friday.  What did we talk about last time?  C basics  Data types  Output with printf()
Week 3 - Monday.  What did we talk about last time?  Math library  Preprocessor directives  Lab 2.
Chapter 6: Iteration Part 1. To be able to program loops with the while, for, and do statements To avoid infinite loops and off-by-one errors To understand.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
Chapter 5 Control Structure (Repetition). Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct.
Control Structures II (Repetition). Objectives In this chapter you will: Learn about repetition (looping) control structures Explore how to construct.
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,
Chapter 04 Control Statements: Part II. OBJECTIVES In this part you will learn: if…else Double-Selection Statement. while Repetition Statement.
CS101 Computer Programming I Chapter 4 Extra Examples.
Week 3 - Wednesday.  What did we talk about last time?  Other C features  sizeof, const  ASCII table  printf() format strings  Bitwise operations.
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
ITP © Ron Poet Lecture 7 1 Repetition. ITP © Ron Poet Lecture 7 2 Easing Repetitive Tasks  Many computing task are repetitive.  Checking all known foods.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.
Week 6 - Monday.  What did we talk about last time?  while loop examples  Lab 5.
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Introduction to Computing Concepts Note Set 14. What if… You had to print “I love Java” to the screen 125 times. How? 125 lines of ▫ System.out.println(“I.
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
1 Week 9 Loops. 2 Repetition: Loops l Structure: »Usually some initialization code »body of loop »loop termination condition l Several logical organizations.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
LOOPS CHAPTER Topics  Four Types of Loops –while –do…while –for –foreach  Jump Statements in Loops –break –continue 2.
Week 3 - Friday.  What did we talk about last time?  Preprocessor directives  Other C features  sizeof, const  ASCII table  printf() format strings.
Testing Programs with Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
CSC Programming for Science Lecture 12: while & do/while Loops.
Structured Programming The Basics
Recursion Recursion is a fundamental programming technique that can provide an elegant solution certain kinds of problems © 2004 Pearson Addison-Wesley.
Chapter 4 Repetition Statements (loops)
REPETITION CONTROL STRUCTURE
Week 3 - Friday CS222.
Lecture 6 Repetition Richard Gesick.
Lecture 7: Repeating a Known Number of Times
CS1010 Programming Methodology
The nested repetition control structures & Continue Statements
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Looping and Repetition
MSIS 655 Advanced Business Applications Programming
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Outline Altering flow of control Boolean expressions
CMPT 102 Introduction to Scientific Computer Programming
Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
CHAPTER 21 LOOPS 1.
FLUENCY WITH INFORMATION TECNOLOGY
Flow of Control.
Chapter 3 Flow of Control Loops in Java.
Week 2 - Friday CS222.
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Week 3 - Friday

 What did we talk about last time?  Bitwise practice  Precedence  Control flow

Unix is simple. It just takes a genius to understand its simplicity. Dennis Ritchie Unix is simple. It just takes a genius to understand its simplicity. Dennis Ritchie

 Loops can go on forever if you aren’t careful int n = 40; int i = 1; while( i <= 40 ) { printf("%d", i); //supposed to print all the numbers //less than 40, but i never increases } int n = 40; int i = 1; while( i <= 40 ) { printf("%d", i); //supposed to print all the numbers //less than 40, but i never increases }

 Infinite for loops are unusual, but possible:  This situation is more likely: for( ; ; ) printf("Hey!"); for( ; ; ) printf("Hey!"); int i; for(i = 0; i < 10; i++ ) { printf("%d", i); //lots of other code i--; //whoops, maybe changed from while? } int i; for(i = 0; i < 10; i++ ) { printf("%d", i); //lots of other code i--; //whoops, maybe changed from while? }

 Overflow and underflow will make some badly written loops eventually terminate int i; for( i = 1; i <= 40; i-- ) //whoops, should have been i++ printf("%d", i); int i; for( i = 1; i <= 40; i-- ) //whoops, should have been i++ printf("%d", i);

 Being off by one is a very common loop error int i; for( i = 1; i < 40; i++ ) //runs 39 times printf("%d", i); int i; for( i = 1; i < 40; i++ ) //runs 39 times printf("%d", i);

 If the condition isn’t true to begin with, the loop will just be skipped int i; for( i = 1; i >= 40; i++ ) //oops, should be <= printf("%d", i); int i; for( i = 1; i >= 40; i++ ) //oops, should be <= printf("%d", i);

 A misplaced semicolon can cause an empty loop body to be executed  Everything looks good, loop even terminates  But, only one number will be printed: 41  Misplaced semicolon usually makes a while loop infinite int i; for( i = 1; i <= 40; i++ ); //semicolon is wrong { printf("%d", i); } int i; for( i = 1; i <= 40; i++ ); //semicolon is wrong { printf("%d", i); }

 Systems programming concepts  Functions and prototypes

 Read LPI chapter 3 and K&R chapter 4  Project 1 due tonight by midnight!