System Design S.CS301

Similar documents
Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

Programming for Experimental Research. Flow Control

ENGR 1181 MATLAB 09: For Loops 2

Flow Control: Branches and loops

Decision Making in C

INTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from

REPETITIVE EXECUTION: LOOPS

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk

Example: Monte Carlo Simulation 1

COGS 119/219 MATLAB for Experimental Research. Fall 2016 Week 1 Built-in array functions, Data types.m files, begin Flow Control

Advanced Computer Programming

Fundamentals of Programming Session 13

CEMTool Tutorial. Control statements

Java Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

EGR 111 Loops. This lab is an introduction to loops, which allow MATLAB to repeat commands a certain number of times.

The for Loop. Lesson 11

Day06 A. Young W. Lim Mon. Young W. Lim Day06 A Mon 1 / 16

Lecture 7 Tao Wang 1

REPETITION CONTROL STRUCTURE LOGO

Iterative Languages. Scoping

Chapter 4: Making Decisions

For Loop. Variations on Format & Specific Examples

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

Prepared by: Shraddha Modi

Chapter 4: Making Decisions

Introduction. C provides two styles of flow control:

Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala

LECTURE 5 Control Structures Part 2

CHAPTER : 9 FLOW OF CONTROL

Chapter 2: Functions and Control Structures

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

CS110D: PROGRAMMING LANGUAGE I

ECE 102 Engineering Computation

Lab 09: Advanced SQL

Flow Control. CSC215 Lecture

Example. Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct.

LECTURE 04 MAKING DECISIONS

While Loops CHAPTER 5: LOOP STRUCTURES. While Loops. While Loops 2/7/2013

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

1 Truth. 2 Conditional Statements. Expressions That Can Evaluate to Boolean Values. Williams College Lecture 4 Brent Heeringa, Bill Jannen

204111: Computer and Programming

Chapter 6. Section 6.4 Altering the Flow of Control. CS 50 Hathairat Rattanasook

function [s p] = sumprod (f, g)

EGR 111 Loops. This lab is an introduction to loops, which allow MATLAB to repeat commands a certain number of times.

Step by step set of instructions to accomplish a task or solve a problem

Short Version of Matlab Manual

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

Week 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.

Module 4: Decision-making and forming loops

Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999

Sorting Pearson Education, Inc. All rights reserved.

Loops / Repetition Statements

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Statements execute in sequence, one after the other, such as the following solution for a quadratic equation:

Loops / Repetition Statements. There are three loop constructs in C. Example 2: Grade of several students. Example 1: Fixing Bad Keyboard Input

MATLAB for Chemical engineer

Object-Oriented Programming in Java

Computers Programming Course 7. Iulian Năstac

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Programming Lecture 4

C++ Programming: From Problem Analysis to Program Design, Third Edition

Dept. of CSE, IIT KGP

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

ECE 202 LAB 3 ADVANCED MATLAB

COMPUTER PROGRAMMING LOOPS

n Group of statements that are executed repeatedly while some condition remains true

Lecture 10. Daily Puzzle

Branches, Conditional Statements

Instructor: SIR MUHAMMAD NAVEED Created by: ARSLAN AHMED SHAAD ( ) MUHAMMAD BILAL ( ) ISIT:

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB

Flow of Control. Selection. if statement. True and False in C False is represented by any zero value. switch

Lab 5 - Repetition. September 26, 2018

Programming Languages

CS 221 Lecture. Tuesday, 4 October There are 10 kinds of people in this world: those who know how to count in binary, and those who don t.

Looping. Arizona State University 1

7 Control Structures, Logical Statements

Repetition Structures II

Chapter 4: Making Decisions. Copyright 2012 Pearson Education, Inc. Sunday, September 7, 14

Repetition Structures Chapter 9

Armstrong Atlantic State University Engineering Studies MATLAB Marina Sorting Primer

MATLAB Operators, control flow and scripting. Edited by Péter Vass

Functions. Lecture 6 COP 3014 Spring February 11, 2018

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

C/C++ Programming for Engineers: Matlab Branches and Loops

Conditional Control Structures. Dr.T.Logeswari

4.0 Programming with MATLAB

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

Problem Solving and 'C' Programming

Programming Lecture 4

C++ Programming Lecture 7 Control Structure I (Repetition) Part I

Repetition CSC 121 Fall 2014 Howard Rosenthal

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Theory of control structures

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

Transcription:

System Design S.CS301 (Autumn 2015/16) Page 1

Өмнөх хичээлээр юу үзсэн бэ? o m файлууд o Скрипт файл, түүнийг үүсгэх o Функц файл o Оролт гаралтын аргументүүд o Скрипт ба функц м файлуудын ялгаа o ҮС-н командууд o Каталогтой ажиллах команд o Файлтай ажиллах команд (Autumn 2015/16) Page 2

Today we will learn Relational and logical operators Switch statement Nested switch Statements While loop For loop Control of loop (Autumn 2015/16) Page 3

Relational and logical operators A relational operator compares two numbers by determining whether a comparison is true or false. (Autumn 2015/16) Page 4

switch command A switch block conditionally executes one set of statements from several choices. Each choice is covered by a case statement. (Autumn 2015/16) Page 5

Example - 1 (Autumn 2015/16) Page 6

Introduction The switch block tests each case until one of the case expressions is true. A case is true when (Autumn 2015/16) Page 7

Example 2 (Autumn 2015/16) Page 8

Example 3 (Autumn 2015/16) Page 9

The Nested switch Statements It is possible to have a switch as part of the statement sequence of an outer switch. Even if the case constants of the inner and outer switch contain common values, no conflicts will arise. (Autumn 2015/16) Page 10

Example 4 (Autumn 2015/16) Page 11

Loop Types A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages (Autumn 2015/16) Page 12

While loop The while loop repeatedly executes statements while condition is true. The while loop repeatedly executes program statement(s) as long as the expression remains true. An expression is true when the result is nonempty and contains all nonzero elements (logical or real numeric). Otherwise, the expression is false (Autumn 2015/16) Page 13

Example 5 (Autumn 2015/16) Page 14

The for Loop A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. (Autumn 2015/16) Page 15

Values of for loop (Autumn 2015/16) Page 16

Example 6 (Autumn 2015/16) Page 17

Loop Control Statements Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. The break statement terminates execution of for or while loop. Statements in the loop that appear after the break statement are not executed. In nested loops, break exits only from the loop in which it occurs. Control passes to the statement following the end of that loop. (Autumn 2015/16) Page 18

Flow diagram (Autumn 2015/16) Page 19

Continue Statement The continue statement is used for passing control to next iteration of for or while loop. The continue statement in MATLAB works somewhat like the break statement. Instead of forcing termination, however, 'continue' forces the next iteration of the loop to take place, skipping any code in between. (Autumn 2015/16) Page 20

Conditional Expressions 1 x=10; y=20; 1. disp(x < y); 2. disp(x <= 10); 3. disp(x == y); 4. disp((0 < x) & (y < 30)); 5. disp((x > 10) (y > 100)); 6. disp(~(x > 10)); (Autumn 2015/16) Page 21

Conditional Expressions 2 area=[ 1 4 9 16 25 36 ]; perimeter=[ 4 8 12 16 20 24 ]; disp(area < perimeter);? 1 1 1 0 0 0 disp(area(area < perimeter));? 1 4 9 (Autumn 2015/16) Page 22

Exercise Дурын А тоо өгөгджээ. Өгөгдсөн тоо эерэг бол тоог 10-аар хорогдуулж, сөрөг бол 10-р нэмэгдүүлж гарга. Дээрх нөхцөлүүдийг биелүүлэхгүй бол өгөгдсөн тоон дээр 81-г нэмээд гарсан тооноос квадрат язгуур гарга. (Autumn 2015/16) Page 23

What we learned today? Logical operation for conditional commands Multi selection command Repeat several commands by while and for statements Usage of the break and continue keywords To program linear equations using by built-in functions Solve linear equations by script files (Autumn 2015/16) Page 24

End of Any questions? (Autumn 2015/16) Page 25