Lesson 3. Controlling program flow. Loops. Methods. Arrays.

Slides:



Advertisements
Similar presentations
Control Structures.
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':
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Creating PHP Pages Chapter 7 PHP Decisions Making.
Objectives Using functions to organize PHP code
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
true (any other value but zero) false (zero) expression Statement 2
Chapter 4 Functions and Control Structures PHP Programming with MySQL.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
C++ for Engineers and Scientists Third Edition
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Module 3: Steering&Arrays #1 2000/01Scientific Computing in OOCourse code 3C59 Module 3: Algorithm steering elements If, elseif, else Switch and enumerated.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Lesson - 5. Introduction While programming, we usually need to decide the path of the program flow according to the parameters and conditions. Actually.
3. Controlling Program Flow Methods, parameters, and return values Boolean expressions Conditional branching Loops.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
JavaScript, Fourth Edition
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.
CSI 3125, Preliminaries, page 1 Control Statements.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
1 Review for Midterm 2 Aaron Bloomfield CS 101-E.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
5 Copyright © 2004, Oracle. All rights reserved. Controlling Program Flow.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
JavaScript, Sixth Edition
JAVA PROGRAMMING Control Flow. Jeroo: Finish Activities 1-7 Finish InputTest program w/changes.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Branching statements.
CHAPTER 4 DECISIONS & LOOPS
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Chapter 3: Decisions and Loops
Loops in Java.
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Prepared By: G.UshaRani B.Pranalini A.S.Lalitha
Expressions and Control Flow in JavaScript
Control Structures.
الكلية الجامعية للعلوم التطبيقية
IF if (condition) { Process… }
In this class, we will cover:
C# Basics These slides are designed for Game Design Class
During the last lecture we had a discussion on Data Types, Variables & Operators
Exam 1 Material Study Guide
CS139 October 11, 2004.
Visual Basic – Decision Statements
Objectives In this chapter, you will:
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Computer Science Core Concepts
CMPE212 – Reminders The other four assignments are now posted.
Program Flow.
Fundamental Programming
In this class, we will cover:
Decision making and control functions
Presentation transcript:

Lesson 3. Controlling program flow. Loops. Methods. Arrays. Programming in C# Lesson 3. Controlling program flow. Loops. Methods. Arrays.

Three types of program flow Straight line Chosen depending on a given condition Repeated according to a given condition

Making decisions

Making decisions in UML diagram

Two main constructions to control program flow IF/ELSE SWITCH

IF/ELSE construction if (condition) statement or block we do if the condition is true else statement or block we do if the condition is false

Conditions and Relational Operators == > < <= >= != ! Only two types of values: true or false

Combining Logical Operators && ||

Combining Logical Operators sample:

Combining Logical Operators inversed sample:

SWITCH construction switch (value) { } case ‘option 1’: statement or block we do if value equals ‘option 1’ break; case ‘option 2’: statement or block we do if value equals ‘option 2’ case ‘option 3’: statement or block we do if value equals ‘option 3’ default: statement or block we do in all other cases }

Loops

Loops in UML diagram

Four main types of loops DO-WHILE WHILE FOR FOREACH

DO-WHILE Loop do statement or block while (condition);

DO-WHILE Loop Sample

WHILE Loop while (condition) statement or block

WHILE Loop Sample

FOR Loop for (setup; finish test; update) things we want to do a given number of times

FOR Loop Sample

Breaking Out of Loops break continue

Methods Reusing a piece of code Break down a large task into a number of smaller ones

Simple method sample

Method Parameters

Method Parameters

Method Signature Type of Parameters Number of Parameters Return Type

Parameter Passing By Value

Parameter Passing By Reference

Passing Parameters as “out” Reference

What else should we know about method parameters? Default parameters Variable number of parameters Method overload

Arrays

Array declaration

Array in Memory

Array Elements

Array Elements Initialization

Managing Array Sizes

Two Dimensional Arrays

Two Dimensional Array Declaration

Arrays and Lookup Tables