G6DICP - Lecture 5 Control Structures.

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

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':
Fundamental of C programming
Karel J Robot Chapter 6.
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Tonight’s JavaScript Topics 1 Conditional Statements: if and switch The Array Object Looping Statements: for, while and do-while.
Conditional Statements and Loops. Today’s Learning Goals … Learn about conditional statements and their structure Learn about loops and their structure.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
Programming Lecture #4 CS 101 Autumn 2006 Tariq Jadoon.
Switch Statement switch (month) { case 9: case 4: case 6: case 11: days = 30; break; case 2: days = 28; if (year % 4 == 0) days = 29; break; default: days.
1 CS 105 Lecture 6 While Loops Wed, Feb 16, 2011, 5:13 pm.
C Programming Constants and Control Structures. Constants Can be defined in two ways. –Traditional Method –#define PI 3.14 #define is a preprocessor command.
Introduction to LabVIEW Seth Price Department of Chemical Engineering New Mexico Tech Rev. 10/5/14.
The switch StatementtMyn1 The switch Statement Sometimes there can be a multiple-choice situation, in which you need to execute a particular set of statements.
1 CSC103: Introduction to Computer and Programming Lecture No 11.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
Object Oriented Programming Lecture 4: Flow Control Mustafa Emre İlal
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
For Code Next For Code Next A loop is a segment of a code that repeats (changing slightly each time)
Working with Loops, Conditional Statements, and Arrays.
Chapter 9 Control Structures.
Lecture 01b: C++ review Topics: if's and switch's while and for loops.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
XP Tutorial 3 New Perspectives on JavaScript, Comprehensive1 Working with Arrays, Loops, and Conditional Statements Creating a Monthly Calendar.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Sensor Information: while loops and Boolean Logic.
Follow up from lab See Magic8Ball.java Issues that you ran into.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
CS1010 Discussion Group 11 Week 5 – Functions, Selection, Repetition.
CHAPTER 4 DECISIONS & LOOPS
Chapter 9 Repetition.
ECE Application Programming
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Loops in Java.
Ch 7: JavaScript Control Statements I.
Expressions and Control Flow in JavaScript
Web Programming– UFCFB Lecture 16
Chapter 19 JavaScript.
Chapter 5 Repetition.
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
CS149D Elements of Computer Science
Loop Control Structure.
Looping and Repetition
Iteration with While You can say that again.
Chapter 9 Control Structures.
Selection (if-then-else)
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
LabVIEW.
Intro to Programming CURIE 2011.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
It’s Time for a Break!!!.
Seating “chart” Front - Screen rows Back DOOR.
Fundamental Programming
Introduction to Repetition
Introduction to Repetition
Loops CGS3416 Spring 2019 Lecture 7.
How to allow the program to know when to stop a loop.
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Looping and Repetition
Introduction to Python
Animate a Sprite. By M, M and C P6
Presentation transcript:

G6DICP - Lecture 5 Control Structures

Loops A block of code is repeated A pre-defined number of times Until a certain (boolean) condition is met Determinate vs indeterminate The contents of variables often change in each cycle. Beware of perpetual loops!

For Loops Probably the most common type of loop. for ( starting condition; continuing condition; change each cycle ) for ( a=1; a<=10; a++ ) { ... }

While Loops while (continuing condition) while (a<=10) { ... }

Do.. while Loops do { ... } while (continuing condition) do { ... } while (a<=10)

Switch switch (answer) { case ‘y’ : { ... } case ‘n’ : { ... } default : { ... } } case ‘y’ : { ... }; break; case ‘n’ : { ... }; break; default : { ... }; break;