Week 10 Recap CSE 115 Spring 2007. For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Chapter 4: Control Structures I (Selection)
Chapter 2 Flow of Control. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-2 Learning Objectives Boolean Expressions Building, Evaluating.
Chapter 4 - Control Statements
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
MONTEGO BAY HIGH SCHOOL INFORMATION TECHNOLOGY THE EXCEL IF FUNCTION.
3. S/E with Control Structures 3.1 Relational Operators and Expressions 3.2 If and if-else Statements 3.3 The Type Double 3.4 Program Design with the While.
Conditional statements and Boolean expressions. The if-statement in Java (1) The if-statement is a conditional statement The statement is executed only.
CS-1010 Dr. Mark L. Hornick 1 Selection Statements and conditional expressions.
Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if …
CSE 115 Week 11 March , Announcements March 26 – Exam 7 March 26 – Exam 7 March 28 – Resign Deadline March 28 – Resign Deadline Lab 7 turned.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
If Statements Sections 1.25, Control Structures o All code thus far executes every line of code sequentially o We want to be able to repeat,
General Computer Science for Engineers CISC 106 Lecture 10 Roger Craig Computer and Information Sciences 3/06/2009.
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Week 11 Recap CSE 115 Spring Want to write a programming language? You’ll need three things: You’ll need three things: –Sequencing –Selection Polymorphism.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Unit 5 – “Watch Out!”. Introduction New Topics Case Structures New Functions Less? Comparison Function Ultrasonic Sensor.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Chapter 3: Data Types and Operators JavaScript - Introductory.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
CS&E 1111 ExLogic Microsoft Excel Logical Functions Objectives: Using Boolean Logic in Spreadsheets l Relational operators l Boolean operators –Functions.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
1 Week 6 Branching. 2 What is “Flow of Control”? l Flow of Control is the execution order of instructions in a program l All programs can be written with.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Relational and Boolean Operators CSIS 1595: Fundamentals of Programming and Problem Solving 1.
More Perl Data Types Scalar: it may be a number, a character string, or a reference to another data type. -the sigil $ is used to denote a scalar(or reference)
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 4: Understand and implement Decisions.
Murach, Chapter 5. Common Control Structures Selection: The IF statement Case: The Select Case statement Iteration: Loops 9/28/20082.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Catie Welsh February 9,  Friday - No Lab! ◦ Bring questions on Project 2  Lab 3 due on Friday 2.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Today… Operators, Cont. Operator Precedence Conditional Statement Syntax. Winter 2016CISC101 - Prof. McLeod1.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
if ( condition ) statement; if is a Java reserved word The condition must be a boolean expression. It must evaluate to either true or false.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Control Flow (Python) Dr. José M. Reyes Álamo.
Relational Operator and Operations
Sequence, Selection, Iteration The IF Statement
Loops in Java.
Debugging and Random Numbers
Expressions and Control Flow in JavaScript
Chapter 5 Structures.
Boolean Expressions and If statements
Computers & Programming Languages
Relational Operators Operator Meaning < Less than > Greater than
Iterator.
Control Structures: for & while Loops
Chapter 8: More on the Repetition Structure
Logical Operations In Matlab.
LabVIEW.
Computer Science Core Concepts
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Code Refresher Test #1 Topics:
Expressions.
Flow of Control.
Relational Operators.
If-statements & Indefinite Loops
Seating “chart” Front - Screen rows Back DOOR.
PROGRAM FLOWCHART Iteration Statements.
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Types, Truth, and Expressions
Presentation transcript:

Week 10 Recap CSE 115 Spring 2007

For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each loop to help us iterate over all elements of that collection. When we have a collection and want to do something to all elements of that collection we use the for-each loop to help us iterate over all elements of that collection.

For-each loop syntax for(Type identifier1: identifier2) { //code to execute for each element } Where: Where: –identifier2 is the name of the collection that you are iterating over –Type identifier1 is the creation of a reference to each element of the collection to use as you are iterating.

If-statements  Selection based on the value of a boolean expression.

If-statement syntax if (booleanExpression) { //code to be executed if //booleanExpression evaluates to //true}

Boolean expressions Expressions that evaluate to either true or false Expressions that evaluate to either true or false boolean is a type built into Java boolean is a type built into Java However, boolean is not a class However, boolean is not a class

Boolean values and operators Methods can return boolean values Methods can return boolean values Can combine boolean values using logic operators Can combine boolean values using logic operators && (logical and) || (logical or) ! (logical not)

Operators that return a boolean value Comparison operators return boolean values as well. These operators work on numeric values. Comparison operators return boolean values as well. These operators work on numeric values. < (less than) < (less than) > (greater than) > (greater than) <= (less than or equal to) <= (less than or equal to) >= (greater than or equal to) >= (greater than or equal to)

Operators that return a boolean value There are two equality operators in Java: There are two equality operators in Java: == (equality) != (not equal) These work on numeric values as you would expect from arithmetic These work on numeric values as you would expect from arithmetic But are also defined on references where they compare if the references are the same. But are also defined on references where they compare if the references are the same.