Welcome back to Software Development!

Slides:



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

Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
CS Data Structures Appendix 1 How to transfer a simple loop- expression to a recursive function (factorial calculation)
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Loops Repeat after me …. Loops A loop is a control structure in which a statement or set of statements execute repeatedly How many times the statements.
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
The foreach LooptMyn1 The foreach Loop The foreach loop gives an easy way to iterate over arrays. foreach works only on arrays, and will issue an error.
An Introduction to Textual Programming
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
For Loops 1 Loops/Iteration Used to repeat an action Must have a STOP condition Three flavors - for, while, do/while Which loop to use? task with a specific.
REPETITION CITS1001. Scope of this lecture Repetition for loops while loops 2.
Computer Science 111 Fundamentals of Programming I The while Loop and Indefinite Loops.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
 Wednesday, 9/18/02, Slide #1 CS106 Introduction to CS1 Wednesday, 9/18/02  QUESTIONS?? HW #1 due today at 5!!  Today: Loops, and two new data types.
For loops in programming Assumes you have seen assignment statements and print statements.
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Research Topics in Computational Science. Agenda Survey Overview.
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
Validation final steps Stopping gaps being entered in an input.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.
Chapter 5 Repetition. 2 Objectives You should be able to describe: The while Statement cin within a while Loop The for Statement The do Statement Common.
CSC 4630 Meeting 17 March 21, Exam/Quiz Schedule Due to ice, travel, research and other commitments that we all have: –Quiz 2, scheduled for Monday.
ITM © Port, Kazman1 ITM 352 Flow-Control: Loops Lecture #8.
LOOPS CHAPTER Topics  Four Types of Loops –while –do…while –for –foreach  Jump Statements in Loops –break –continue 2.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
CSC 4630 Perl 3 adapted from R. E. Beck. Problem But we worked on it first: Input: Read from a text file named in a command line argument Output: List.
1 CSC103: Introduction to Computer and Programming Lecture No 9.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
Loops Brent M. Dingle Texas A&M University Chapter 7 – part C (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
UCT Department of Computer Science Computer Science 1015F Iteration
ECE Application Programming
Lesson #5 Repetition and Loops.
Whatcha doin'? Aims: To start using Python. To understand loops.
Introduction To Repetition The for loop
CS161 Introduction to Computer Science
Lesson #5 Repetition and Loops.
Incrementing ITP © Ron Poet Lecture 8.
ITM 352 Flow-Control: Loops
الحلقات التكرارية وجمل الدوران (loops)
Loops The loop blocks you've used in Scratch can all be recreated in C! Loops allow for the repetition of code until a condition is met. There are three.
Lesson #5 Repetition and Loops.
CSC115 Introduction to Computer Programming
Introduction to Programming
Welcome back to Software Development!
Welcome back to Software Development!
Welcome back to Software Development!
M150: Data, Computing and Information
Welcome back to Software Development!
CHAPTER 21 LOOPS 1.
Welcome back to Software Development!
Lesson #5 Repetition and Loops.
Welcome back to Software Development!
Repetition Statements (Loops) - 2
Repetition Statements
True / False Variables.
Learning Plan 4 Looping.
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
EECE.2160 ECE Application Programming
Looping and Repetition
Presentation transcript:

Welcome back to Software Development!

Due Today… Reading assignment: Clear/Unclear windows on pages 87-97

Tomorrow…

Tomorrow… Test on loops

Loops Review

Loops Review 3 types of loops:

Loops Review 3 types of loops: while

Loops Review 3 types of loops: while used when you don’t know how many times to loop

Loops Review 3 types of loops: while for used when you don’t know how many times to loop for

Loops Review 3 types of loops: while for used when you don’t know how many times to loop for used when you do know how many times to loop

Loops Review 3 types of loops: while for foreach used when you don’t know how many times to loop for used when you do know how many times to loop foreach

Loops Review 3 types of loops: while for foreach used when you don’t know how many times to loop for used when you do know how many times to loop foreach used to work on parts of a group, one at a time

All Loops…

All Loops… Use a sentry variable

All Loops… Use a sentry variable Also called the loop control variable

All Loops… Use a sentry variable First: Initialize the sentry variable Also called the loop control variable First: Initialize the sentry variable

All Loops… Use a sentry variable First: Initialize the sentry variable Also called the loop control variable First: Initialize the sentry variable If you don’t, you likely won’t be able to even get into the loop

All Loops… Use a sentry variable First: Initialize the sentry variable Also called the loop control variable First: Initialize the sentry variable If you don’t, you likely won’t be able to even get into the loop Next: Check the sentry variable to see if keep looping

All Loops… Use a sentry variable First: Initialize the sentry variable Also called the loop control variable First: Initialize the sentry variable If you don’t, you likely won’t be able to even get into the loop Next: Check the sentry variable to see if keep looping Finally: Change (often increment) the sentry variable

All Loops… Use a sentry variable First: Initialize the sentry variable Also called the loop control variable First: Initialize the sentry variable If you don’t, you likely won’t be able to even get into the loop Next: Check the sentry variable to see if keep looping Finally: Change (often increment) the sentry variable If you don’t, you won’t be able to exit the loop…infinite loop

While Loop

While Loop Used when you don’t know how many times you need to loop

While Loop Used when you don’t know how many times you need to loop Init the sentry variable outside and before the loop

While Loop Used when you don’t know how many times you need to loop Init the sentry variable outside and before the loop Check the sentry variable in the while statement condition

While Loop Used when you don’t know how many times you need to loop Init the sentry variable outside and before the loop Check the sentry variable in the while statement condition Change the sentry variable in the body of the while loop

While Loop Used when you don’t know how many times you need to loop Init the sentry variable outside and before the loop Check the sentry variable in the while statement condition Change the sentry variable in the body of the while loop Often increment the sentry when simply counting

While Loop while ( check sentry ) Used when you don’t know how many times you need to loop Init the sentry variable outside and before the loop Check the sentry variable in the while statement condition Change the sentry variable in the body of the while loop Often increment the sentry when simply counting while ( check sentry )

While Loop Example int counter; // create sentry variable counter = 0; // init sentry variable while ( counter < 5 ) // loop until counter >= 5 { Console.WriteLine(“Looped {0} times.”, counter); counter++; // increment counter }

For Loop

For Loop Used when you *do* know how many times you need to loop

For Loop Used when you *do* know how many times you need to loop for (

For Loop for ( init the sentry ; Used when you *do* know how many times you need to loop for ( init the sentry ;

For Loop for ( init the sentry ; check the sentry ; Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ;

For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry )

For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry ) In the for statement:

For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry ) In the for statement: 1st part: Init the sentry variable

For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry ) In the for statement: 1st part: Init the sentry variable 2nd part: Check the sentry variable

For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry ) In the for statement: 1st part: Init the sentry variable 2nd part: Check the sentry variable 3rd part: Change the sentry variable

For Loop Used when you *do* know how many times you need to loop for ( init the sentry ; check the sentry ; change the sentry ) In the for statement: 1st part: Init the sentry variable 2nd part: Check the sentry variable 3rd part: Change the sentry variable Often increment the sentry when simply counting

For Loop int counter; // create sentry variable // Loop until counter >= 5 for ( counter = 0 ; counter < 5 ; counter++ ) { Console.WriteLine(“Looped {0} times.”, counter); }

For Loop int counter; // create sentry variable // Loop until counter >= 5 for ( counter = 0 ; counter < 5 ; counter++ ) { Console.WriteLine(“Looped {0} times.”, counter); } Init sentry variable

For Loop int counter; // create sentry variable // Loop until counter >= 5 for ( counter = 0 ; counter < 5 ; counter++ ) { Console.WriteLine(“Looped {0} times.”, counter); } Init sentry variable Check sentry variable

For Loop int counter; // create sentry variable // Loop until counter >= 5 for ( counter = 0 ; counter < 5 ; counter++ ) { Console.WriteLine(“Looped {0} times.”, counter); } Init sentry variable Check sentry variable Increment sentry variable

Foreach Loop

Foreach Loop Used to work on parts of a group, one at a time

Foreach Loop Used to work on parts of a group, one at a time The sentry variable is created in the foreach statement

Foreach Loop Used to work on parts of a group, one at a time The sentry variable is created in the foreach statement The foreach automatically checks and changes the sentry variable

Foreach Loop foreach ( Used to work on parts of a group, one at a time The sentry variable is created in the foreach statement The foreach automatically checks and changes the sentry variable foreach (

Foreach Loop foreach ( create sentry Used to work on parts of a group, one at a time The sentry variable is created in the foreach statement The foreach automatically checks and changes the sentry variable foreach ( create sentry

Foreach Loop foreach ( create sentry in Used to work on parts of a group, one at a time The sentry variable is created in the foreach statement The foreach automatically checks and changes the sentry variable foreach ( create sentry in

Foreach Loop foreach ( create sentry in group to work with ) Used to work on parts of a group, one at a time The sentry variable is created in the foreach statement The foreach automatically checks and changes the sentry variable foreach ( create sentry in group to work with )

Foreach Example string myString; // create sentence variable myString = “This is a multi-word sentence”; // init sentence // Loop through the sentence word by word foreach ( string word in myString.Split() ) { Console.WriteLine(“The next word is: {0}”, word); }

Foreach Example string myString; // create sentence variable myString = “This is a multi-word sentence”; // init sentence // Loop through the sentence word by word foreach ( string word in myString.Split() ) { Console.WriteLine(“The next word is: {0}”, word); } Create sentry variable

Foreach Example string myString; // create sentence variable myString = “This is a multi-word sentence”; // init sentence // Loop through the sentence word by word foreach ( string word in myString.Split() ) { Console.WriteLine(“The next word is: {0}”, word); } Create sentry variable Automagically check and change sentry variable

Your Task

Your Task Get a multi-word sentence from the user Require that they enter a multi-word sentence Allow up to 3 tries then quit Reprint the sentence with: The first letter of every word capitalized All other letters lower case You have till the end of the period…

Existing Tasks Fix your MathGame program so that the user must enter a number.

Clear and Unclear Windows