FOP: While Loops.

Slides:



Advertisements
Similar presentations
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Advertisements

CS0004: Introduction to Programming Repetition – Do Loops.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
Loops – While, Do, For Repetition Statements Introduction to Arrays
CS1061: C Programming Lecture 8: Repetition A. O’Riordan, 2004.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Copyright © Texas Education Agency, Computer Programming For Loops.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
5.05 Apply Looping Structures
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”);
Python quick start guide
COMP 1001: Introduction to Computers for Arts and Social Sciences Programming in Scratch Monday, May 16, 2011.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Using Shortcut Arithmetic Operators Accumulator: A variable that is used to total. Its value is repeatedly increased by some amount. Java provides shortcuts.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
L OO P S While writing a program, there may be a situation when you need to perform some action over and over again. In such situation you would need.
CS 100 Introduction to Computing Seminar October 7, 2015.
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.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Decision Making: while loops and Boolean Logic. While Loops A while loop is a structure within ROBOTC which allows a section of code to be repeated as.
Comp1004: Loops and Arrays I Whiles, For and Arrays[]
IST 210: PHP Logic IST 210: Organization of Data IST2101.
CMSC201 Computer Science I for Majors Lecture 07 – While Loops
Trace Tables In today’s lesson we will look at:
Control Flow (Python) Dr. José M. Reyes Álamo.
Chapter 6: Loops.
Chapter 4 Repetition Statements (loops)
FOP: JavaScript Arrays(Lists)
CS161 Introduction to Computer Science
Lesson 05: Iterations Class Chat: Attendance: Participation
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
While Loops in Python.
While Loops Chapter 3.
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.
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
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
Iteration with While You can say that again.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Outline Altering flow of control Boolean expressions
While Loops and If-Else Structures
Repetition Structures
Nate Brunelle Today: Repetition, Repetition
Loops CIS 40 – Introduction to Programming in Python
Module 4 Loops.
3.5- The while Statement The while statement has the following syntax:
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 6: Repetition Statements
Repetition In today’s lesson we will look at:
3.1 Iteration Loops For … To … Next 18/01/2019.
Introduction to Repetition Structures
ICT Programming Lesson 3:
CSCI N207 Data Analysis Using Spreadsheet
FLUENCY WITH INFORMATION TECNOLOGY
Simple Branches and Loops
PROGRAM FLOWCHART Iteration Statements.
While Loops in Python.
Chapter 3 Flow of Control Loops in Java.
while Loops Looping Control Statement
Looping and Repetition
Presentation transcript:

FOP: While Loops

While Loops: Loops are an extremely important programming concept that is useful for repeating certain lines of code over and over again. Today we will be focusing on the WHILE loop While something is true, keep repeating until that something is false. var count = 0; while( count < 5){ console.log(count); count = count + 1; }

Infinite Loops: Depending on how you structure your loops, you may run into the problem of your loop running forever which is a big problem. If your Boolean expression never becomes false then your code will run forever which may cause your browser or computer to crash. var count = 0; while( count < 5 ){ // Infinite Loop because count will remain zero every iteration console.log( count ); // Since count never changes the Boolean expression will remain true } //The code will just print out 0 forever If you are going to use a loop you MUST make sure that the Boolean expression controlling the loop can eventually become false. That’s up to you the programmer.

Debug Console Feature: If you run your program you can check the value of your variables at the end of the program by simply typing the name of the variable in your debug console.

Debug Console Feature: You can also have your code stop at specific lines while your program is running so that you can see if your program is behaving the way you intended. To do this just click on the number of the line in your code that you want to stop at. Now when you run your code it will stop at line 3 and for you to “Continue”, you just click or “Step over” to resume your code

While Loops and IF Statements: In a while Loop you can use similar Boolean expressions like you would in an IF- statement. Look at the example below: var die1 = -1; var die2 = -1; while( die1 < 3 && die2 < 3){ die1 = randomNumber(1,6); die2 = randomNumber(1,6); } While loops and IF-statements are fairly similar in how they are structured and the way each evaluates Boolean expressions. While loops just repeat over and over until the condition becomes false.

Math Operators: ++ Operator -- Operator var count = 0; count++; //Now count is 1 -- Operator var count = 10; count--; // Now count is 9

Math Operators: += Operator -= Operator var count = 0; count += 3; // Now count is 3; count+=3;` -= Operator var count = 10; count -= 4; //Now count is 6 Count-=10;

IF statements within Loops: You can combine multiple programming concepts together as you are programming. You can place a loop inside a loop You can place a conditional( IF ) statement within a loop You can place a loop inside a conditional ( IF ) statement You can place a conditional( IF ) statement inside a conditional( IF ) statement. Your assignment today is to complete both Stage 11 and Stage 12 In stage 11 it is encouraged you try to finish puzzle 12 and puzzle 13 but it isn’t mandatory In stage 12 is where you will be given less guidance and you will learn a lesson about probability You will have an IF-statement within some of your loops so make sure you understand how to properly place these conditional statements.