CS149D Elements of Computer Science

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
Tonight’s JavaScript Topics 1 Conditional Statements: if and switch The Array Object Looping Statements: for, while and do-while.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Control Structures Nested ifs, switch statements.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
COMP 110 Switch Statements and Loops Tabitha Peck M.S. February 6, 2008 MWF 3-3:50 pm Philips
Lecture 17: 10/29/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Lecture 18: 10/31/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Previously Repetition Structures While, Do-While, For.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Lecture 01b: C++ review Topics: if's and switch's while and for loops.
REPETITION STATEMENTS - Part1  Also called LOOP STATEMENTS OR LOOP STRUCTURES 1 C++ Statements that repeat one or more actions while some condition is.
CSI 3125, Preliminaries, page 1 Control Statements.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
1 CSC103: Introduction to Computer and Programming Lecture No 9.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
BIL 104E Introduction to Scientific and Engineering Computing Lecture 6.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
UCT Department of Computer Science Computer Science 1015F Iteration
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
The switch Statement, and Introduction to Looping
Compound Condition Break , Continue Switch Statements in Java
Unit-1 Introduction to Java
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Chapter 2.2 Control Structures (Iteration)
Programming Fundamentals
Programming Fundamentals
CS149D Elements of Computer Science
Bools & Ifs.
Control Structures.
Loop Control Structure.
Looping and Repetition
Loops October 10, 2017.
- Additional C Statements
IF if (condition) { Process… }
CS170 Computer Organization and Architecture I
Conditional Construct
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
3 Control Statements:.
Repetition Control Structure
CS150 Introduction to Computer Science 1
Looping III (do … while statement)
Lecture Notes – Week 2 Lecture-2
CS149D Elements of Computer Science
CS149D Elements of Computer Science
Program Flow.
CS149D Elements of Computer Science
CS149D Elements of Computer Science
do/while Selection Structure
CS148 Introduction to Programming II
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
CS148 Introduction to Programming II
Dale Roberts, Lecturer IUPUI
CS149D Elements of Computer Science
Control Statements Paritosh Srivastava.
CS149D Elements of Computer Science
CS148 Introduction to Programming II
EECE.2160 ECE Application Programming
CS148 Introduction to Programming II
CS148 Introduction to Programming II
Presentation transcript:

CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture 19: 11/5/2002 Lecture 19: 11/5/2002 CS149D Fall 2002

Outline Selection Statements cont. Switch statement Looping While statement Lecture 19: 11/5/2002 CS149D Fall 2002

Selection Statements cont. Switch statement switch (expression) { case value1: statement(s); break; case value2: statement(s); break; case valuen: statement(s); break; default: statement(s); } if ( i == 1) x = x +1; else if (i == 2) y = y +1; else if (i == 3) z = z+1; else if (i == 4) T = T +1; Is there a better way? switch(i) { case 1: x = x+1; break; case 2: y = y+1; break; case 3: z = z+1; break; case 4: T = T+1; } Can be rewritten as Lecture 19: 11/5/2002 CS149D Fall 2002

Loops Implement Repetitive structures 3 loop structures in C++ while loop, do/while loop, for loop General functionality Execute a certain block of statements until a condition is not true. Lecture 19: 11/5/2002 CS149D Fall 2002

The while loop Condition True ? Execute while Statement(s) Continue to next statement No Yes while (condition) statement; or { statements; } Infinite loop If condition is always true Lecture 19: 11/5/2002 CS149D Fall 2002

The while loop int x = 0,z = 0, y = 5; while (x < y) { z++; cout << z; x++; } What is the program output? Example to convert degrees to radians (page 73-74) Degrees range from 0 to 360 int degrees = 0; while (degrees <= 360) { radians = degrees * PI/180; degrees += 10; } Lecture 19: 11/5/2002 CS149D Fall 2002