While Loops Indefinite Iteration. Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is.

Slides:



Advertisements
Similar presentations
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Advertisements

Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Logic & program control part 3: Compound selection structures.
Solving Problems with Repetition. Objectives At the end of this topic, students should be able to: Correctly use a while statement in a C# program Correctly.
PSEUDOCODE & FLOW CHART
Python Magic Select a Lesson: Why Learn to Code? Basic Python Syntax
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
1 Lab Session-VI CS121 Fall 2000 l HW#2 Assigned l Multiple Choice Selectors l The While Loop l Switch-Case-Break Exercise l The Counter Controlled Loops.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
PROGRAMMING In Lesson 5. RECAP  Complete the starter activity.
An Introduction to Textual Programming
High-Level Programming Languages: C++
Java Programming Constructs 1 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
First tutorial.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Chapter 4 Selection Structures: Making Decisions.
By the end of this session you should be able to...
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
CS 108 Computing Fundamentals Notes for Thursday, February 19, 2015.
30/10/ Iteration Loops Do While (condition is true) … Loop.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 11/06/2012 and 11/07/2012 -Test 3 Study Guide.
Previously Repetition Structures While, Do-While, For.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Python - Selection Selection means selecting (or choosing) what to do next. Should I cycle to school, or ask for a lift? If it’s a sunny day I might cycle.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
CREATING MENUS IN JAVA Mimi Opkins CECS 174. Menus Menus work well for console applications. The menu can be contained within a do-while loop and the.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there.
Programming Fundamentals I Java Programming Spring 2009 Instructor: Xuan Tung Hoang TA: Tran Minh Trung Lab 03.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
GCSE Computing#BristolMet Session Objectives #23 MUST understand what is meant by the programming term iteration SHOULD describe methods of looping used.
GCSE Computing: Programming GCSE Programming Remembering Python.
Introduction to TouchDevelop Lesson 3 – Comments & Lists Created by S. Johnson
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Solving Problems with Repetition Version 1.0. Objectives At the end of this topic, students should be able to: Correctly use a while statement in a C#
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Multi-Selection If-elsif Statement.  In fact, it’s everything in between  Yesterday we learned how to add a control statement that gave us two path.
World of Wokcraft The very best in Single pan cooking themed fantasy gaming!
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
World of Wokcraft The very best in Single pan cooking themed fantasy gaming!
Introduction to Loop. Introduction to Loops: The while Loop Loop: part of program that may execute > 1 time (i.e., it repeats) while loop format: while.
Lecture 4b Repeating With Loops
Iterations Programming Condition Controlled Loops (WHILE Loop)
Control Statement Examples
Introduction to Programming
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Do While (condition is true) … Loop
Introduction to TouchDevelop
IPC144 Introduction to Programming Using C Week 3 – Lesson 2
Do … Loop Until (condition is true)
3.1 Iteration Loops For … To … Next 18/01/2019.
Looping III (do … while statement)
CprE 185: Intro to Problem Solving (using C)
A LESSON IN LOOPING What is a loop?
Clear and Unclear Windows
CprE 185: Intro to Problem Solving (using C)
GCSE Computing.
Presentation transcript:

While Loops Indefinite Iteration

Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is ‘TRUE’ Lets look at the coding on the next slide.

A program which asks the user whether to display hello world or not and thus displaying how many times the user said ‘yes’ Void main () { char answer int count = 0, index = 1; answer=‘y’; while(answer==‘y’) { cout<<endl<<index<<“Hello World”; cout<<endl<<“Do you want another iteration (y/n):”; cin>>answer; index++; count++ } // end loop cout<<“You said yes: “<< (count-1)<<“ times”; }

TASK 1 Write programmer comments along each line explaining the code. Make sure for your game and other programs for the assignment you put programmer comments.

TASK 2 Create a program that tells the user if the user’s input is in the required range or not and thus calculating the attempt of the user. Look at the sample out put of the program below for a hint. Before coding try designing using pseudo code or structured English Enter a number in the range 1 to 100 inclusive: 341 *** you entered 341 – it is not in the required range *** please try again Enter a number in the range 1 to 100 inclusive: 441 *** you entered 441 – it is not in the required range *** please try again Enter a number in the range 1 to 100 inclusive: 0 *** you entered 0 – it is not in the required range *** please try again Enter a number in the range 1 to 100 inclusive: 73 *** you entered 73 – this is in the range You used 4 attempts to enter a valid number

Task 3 Produce a program with a menu driver: a while loop that will continue to iterate until the user chooses the exit option. The menu driver should show a list of numbered options (eg types of calculations) including an exit option, asks the user to enter a choice and then carries out what ever option was chosen (if the choice entered wasn’t a valid option then display an appropriate message). Your program should use the switch case default construct, not if else if else if else.. To do the selection of which bit of code gets called according to the user’s choice.