This is a while loop. The code is done while the condition is true. The code that is done is enclosed in { }. Note that this program has three parts: Housekeeping.

Slides:



Advertisements
Similar presentations
Switch code for Lab 4.2 switch (input) { /* input is a variable that we will test. */ case 'M': printf("The prefix is equal to 1E6.\n"); break; case 'k':
Advertisements

Loops (Part 1) Computer Science Erwin High School Fall 2014.
Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
Chapter 61 Post Test Loop Do statement(s) Loop Until condition Loop is executed once and then the condition is tested. If it is False, the loop is run.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Main task -write me a program
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
For Loops (ProjFor1, ProjFor2, ProjFor3, ProjFor4, textbox, textbox1) Please use speaker notes for additional information!
Logic Structure - focus on looping Please use speaker notes for additional information!
When you start a new world, pick a backgrou nd.. Click on add objects to add objects to your world.
Array - adding to array at run time Please see speaker notes for additional information!
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
Chapter 4 Loops Write code that prints out the numbers Very often, we want to repeat a (group of) statement(s). In C++, we have 3 major ways of.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
Variety of JavaScript Examples Please use speaker notes for additional information!
Count and add list of numbers From user input and from file.
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.
JavaScript Loops Please use speaker notes for additional information!
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
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 /
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
ARITHMETIC OPERATORS COMPARISON/RELATIO NAL OPERATORS LOGIC OPERATORS ()Parenthesis>Greater than &&And ^Exponentiation=>=
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Lecture 5: Layers of Control. Nested while Loops Problem Multiplying two numbers and outputting the result only if they are both less than 5. (i.e. Start.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
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.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
CHAPTER 4 DECISIONS & LOOPS
CSC111 Quick Revision.
The switch Statement, and Introduction to Looping
CS161 Introduction to Computer Science
Programming Logic and Design Fourth Edition, Comprehensive
Chapter 5: Loops and Files.
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Selection By Ramin && Taimoor
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
For Loops October 12, 2017.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Iteration with While You can say that again.
Outline Altering flow of control Boolean expressions
Please use speaker notes for additional information!
Alternate Version of STARTING OUT WITH C++ 4th Edition
Java Programming Loops
Chapter (3) - Looping Questions.
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
What does this do? def revList(L): if len(L) < = 1: return L x = L[0] LR = revList(L[1:]) return LR + x.
the captured notes and redid - hopefully it all works.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Searching an Array or Table
Using Lists and Functions to Create Dialogue
Note the rights settings.
The + can mean concatenate or add
Programs. at the code at the site..
A LESSON IN LOOPING What is a loop?
JavaScript: Control Statements II
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.
Wrapup which is the document write that says the end.
REPETITION Why Repetition?
Presentation transcript:

This is a while loop. The code is done while the condition is true. The code that is done is enclosed in { }. Note that this program has three parts: Housekeeping which sets things up and takes in input. Processing which is the loop and the code inside the loop. Wrapup which prints out the end message after processing is complete.

There are three things that control the loop. I initialize ct at 1. I increment ct inside the loop so it changes. The condition on the loop compares ct to the data_input information. Eventually since I increment ct with every pass, ct will stop being less than or equal to data_input and processing will stop.

When I put in 1 then the loop gets executed because ct with 1 is less than or equal to data_input with 1. Then I increment ct to 2. The loop will not process again because ct of 2 is not less than or equal to data_input of 1. The loop is not entered and the statement after the loop is executed.

I entered a 0 for data_input so the loop does not get executed because the 1 in ct is not less than or equal to the 0 in data_input.

The do loop is structured differently. The loop is always executed once because the checking is at the bottom and so checking is not done unitl the loop has executed once.

If I enter either a 1 or a 0 the loop will get executed once and ct will move up to 2 prior to checking. The check will compare ct at 2 with data_input at 1 or 0 and the loop will not be executed again. Note that it will always be executed once.

In class exercise is to add an if statement to test to see which player won or if it is a tie.

Looking back at another program for a sample of using the if.