尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
CSCI 101
Selection and Looping
Program control, if-else, logical
expressions, for loop
Overview
• Review
• Program control
• if-else statement
– Relational and logical operators
– Logical expressions
• for loop statement
How to write a program?
1. Read the problem statement, and identify
– The input and its range
– The output
– The relationship between the input and the output
(how to compute the output) [Comprehend]
2. Write your thoughts as a sequence of steps.
[Algorithm]
3. Convert these steps to Code. [Program]
4. Test your code and compare your program result
against a human result. [Testing]
Calculate area of a rectangle
(Algorithm  Program)
1. Get height h
 h=input(‘enter height: ’);
2. Get width w
 w=input(‘enter width: ’);
3. Calculate area = h * w
 area = h * w;
4. Display area
 disp (area);
Program Control
• How to control the flow of the program?
– To executes some statements and not the other
based on the input data.
– To make the program takes decision
• How to make some statements executed
several times.
Print the maximum of two numbers
(Algorithm and Program)
1. Get number1 as X  X=input(‘enter num1:’);
2. Get number2 as Y  Y=input(‘enter num2:’);
3. If X > Y  if X>Y
display X disp(X);
Otherwise else
display Y disp(Y);
end
Print the maximum of two numbers
(Program and Testing)
% printmax.m
X=input(‘enter num1:’);
Y=input(‘enter num2:’);
if X>Y
disp(X);
else
disp(Y);
end
>>printmax
enter num1: 5
enter num2: 10
10
>>printmax
enter num1: 8
enter num2: 3
8
5
10
X
Y
8
3
Print two number in ascending order
(Algorithm  Program)
1. Get number1 as X  X=input(‘enter num1:’);
2. Get number2 as Y  Y=input(‘enter num2:’);
3. If X > Y  if X>Y
display Y, X disp(Y); disp(X);
Otherwise else
display X, Y disp(X); disp(Y);
end
Print two number in ascending order
(Program and Testing)
% order2.m
X=input(‘enter num1:’);
Y=input(‘enter num2:’);
if X>Y
disp(Y);
disp(X);
else
disp(X);
disp(Y);
end
>>order2
enter num1: 5
enter num2: 10
5
10
>>order2
enter num1: 8
enter num2: 3
3
8
5
10
X
Y
8
3
If-else statement
if condition
% do this part if condition is true
else
%do this part if the condition is false
end
Condition (use relational operators):
>, <, >=, <=, ==, ~=
Relational Operators
• Relational operators test the Relationship between
two operands (which can be expressions)
• They are a “Truth Statement”, and resolve to either
True (1) or False (0)
Operator Operation
== Equal to
~= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
Logical Operators
• Relational operators are binary operators so they can have only two
operands
• To have a more complicated condition, we need to use logical
operators
• Logic Operators can combine “truth statements” together in helpful
ways. (and, or, not)
Inputs and or not
A B A && B A || B ~A
false false false false true
false true false true true
true false false true false
true true true true false
Logical Expressions Examples
Write the if condition for the following cases:
1. Check if x > y > z
 if x>y && y>z
2. Check if x is greater than y or less than or equal to z
 if x>y || x <=z
3. Check if x does not equal y but equal z
 if x~=y && x==z
4. Check if x is even
 if rem(x,2)==0
X=input(‘enter num1:’);
Y=input(‘enter num2:’);
if X>Y
disp(X);
else
disp(Y);
end
Repeat a program N times
for i=1:1:5
end
Iteration counter
First counter value
Step value
Last counter value
Try it in MATLAB
for i=1:1:5
X=input(‘enter num1:’);
Y=input(‘enter num2:’);
if X>Y
disp(X);
else
disp(Y);
end
end
X
Y
i
How many times these loops will run:
for i=1:2:10 for z=10:2:20
for a=10:-2:1 for x=1:10
?
Calculate sum from 1 to N (Program)
N=input(‘enter a number:’);
sum=0;
for i=1:N
sum=sum+i;
end
disp(sum);
How to sum only even numbers?
N i sum
5 0
1 1
2 3
3 6
4 10
5 15
Calculate factorial of a number N
(Program)
N=input(‘enter a number:’);
f=1;
for i=1:N
f=f*i;
end
disp(f);
N i f
5 1
1 1
2 2
3 6
4 24
5 120
What this program does?
N=input(‘enter a number:’);
sum=0;
for i=1:N
x=input(‘enter a value:’);
sum=sum+x;
end
disp(sum);
N i x sum
5 0
1 3 3
2 5 8
3 0 8
4 -2 6
5 1 7
How to compute the average of N numbers?
Sum only positive numbers?
N=input(‘enter a number:’);
sum=0;
for i=1:N
x=input(‘enter a value:’);
if x>0
sum=sum+x;
end
end
disp(sum);
N i x sum
5 0
1 3 3
2 5 8
3 -3 8
4 -2 8
5 1 9
Sum and Average positive numbers?
N=input(‘enter a number:’);
sum=0;
c=0;
for i=1:N
x=input(‘enter a value:’);
if x>0
sum=sum+x;
c=c+1;
end
End
Avg=sum/c;
disp(sum);
Disp(Avg);
N i x sum c
5 0 0
1 3 3 1
2 5 8 2
3 -3 8 2
4 -2 8 2
5 1 9 3
C is used to count positive numbers

More Related Content

What's hot

Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 
Operators
OperatorsOperators
C Building Blocks
C Building Blocks C Building Blocks
C Building Blocks
imtiazalijoono
 
02 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_0202 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_02
Pooja Gupta
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
Viraj Shah
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & Branching
Hemantha Kulathilake
 
Conditional Control in MATLAB Scripts
Conditional Control in MATLAB ScriptsConditional Control in MATLAB Scripts
Conditional Control in MATLAB Scripts
Shameer Ahmed Koya
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
Muhammad Hammad Waseem
 
C OPERATOR
C OPERATORC OPERATOR
C OPERATOR
rricky98
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
Hemantha Kulathilake
 
Csci101 lect03 algorithms_i
Csci101 lect03 algorithms_iCsci101 lect03 algorithms_i
Csci101 lect03 algorithms_i
Elsayed Hemayed
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
Neeru Mittal
 
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
Muhammad Hammad Waseem
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
Thesis Scientist Private Limited
 
C operators
C operatorsC operators
C operators
GPERI
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
Manoj Tyagi
 
C Operators
C OperatorsC Operators
C Operators
Yash Modi
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
Chukka Nikhil Chakravarthy
 
[ITP - Lecture 09] Conditional Operator in C/C++
[ITP - Lecture 09] Conditional Operator in C/C++[ITP - Lecture 09] Conditional Operator in C/C++
[ITP - Lecture 09] Conditional Operator in C/C++
Muhammad Hammad Waseem
 
Logical and Conditional Operator In C language
Logical and Conditional Operator In C languageLogical and Conditional Operator In C language
Logical and Conditional Operator In C language
Abdul Rehman
 

What's hot (20)

Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Operators
OperatorsOperators
Operators
 
C Building Blocks
C Building Blocks C Building Blocks
C Building Blocks
 
02 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_0202 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_02
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & Branching
 
Conditional Control in MATLAB Scripts
Conditional Control in MATLAB ScriptsConditional Control in MATLAB Scripts
Conditional Control in MATLAB Scripts
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
 
C OPERATOR
C OPERATORC OPERATOR
C OPERATOR
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
Csci101 lect03 algorithms_i
Csci101 lect03 algorithms_iCsci101 lect03 algorithms_i
Csci101 lect03 algorithms_i
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
C operators
C operatorsC operators
C operators
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
C Operators
C OperatorsC Operators
C Operators
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
[ITP - Lecture 09] Conditional Operator in C/C++
[ITP - Lecture 09] Conditional Operator in C/C++[ITP - Lecture 09] Conditional Operator in C/C++
[ITP - Lecture 09] Conditional Operator in C/C++
 
Logical and Conditional Operator In C language
Logical and Conditional Operator In C languageLogical and Conditional Operator In C language
Logical and Conditional Operator In C language
 

Similar to Csci101 lect02 selection_andlooping

Loops in Python
Loops in PythonLoops in Python
Loops in Python
Arockia Abins
 
Csci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionCsci101 lect04 advanced_selection
Csci101 lect04 advanced_selection
Elsayed Hemayed
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study material
To Sum It Up
 
Operators1.pptx
Operators1.pptxOperators1.pptx
Operators1.pptx
HARSHSHARMA840
 
Csci101 lect08a matlab_programs
Csci101 lect08a matlab_programsCsci101 lect08a matlab_programs
Csci101 lect08a matlab_programs
Elsayed Hemayed
 
Software Metrics
Software MetricsSoftware Metrics
Software Metrics
Ehsan Hessami
 
E1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxE1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docx
jacksnathalie
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
ManojKhadilkar1
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
Komal Kotak
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
NishaS88
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
alish sha
 
C important questions
C important questionsC important questions
C important questions
JYOTI RANJAN PAL
 
Here is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docxHere is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docx
trappiteboni
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
Siddique Ibrahim
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
Kuntal Bhowmick
 
Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1
To Sum It Up
 
Python
PythonPython
computer programming and utilization
computer programming and utilizationcomputer programming and utilization
computer programming and utilization
JAYDEV PATEL
 
GE3151_PSPP_UNIT_3_Notes
GE3151_PSPP_UNIT_3_NotesGE3151_PSPP_UNIT_3_Notes
GE3151_PSPP_UNIT_3_Notes
Asst.prof M.Gokilavani
 

Similar to Csci101 lect02 selection_andlooping (20)

Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
Csci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionCsci101 lect04 advanced_selection
Csci101 lect04 advanced_selection
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study material
 
Operators1.pptx
Operators1.pptxOperators1.pptx
Operators1.pptx
 
Csci101 lect08a matlab_programs
Csci101 lect08a matlab_programsCsci101 lect08a matlab_programs
Csci101 lect08a matlab_programs
 
Software Metrics
Software MetricsSoftware Metrics
Software Metrics
 
E1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docxE1 – FundamentalsPlease refer to announcements for details about.docx
E1 – FundamentalsPlease refer to announcements for details about.docx
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
 
Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10Bti1022 lab sheet 9 10
Bti1022 lab sheet 9 10
 
C important questions
C important questionsC important questions
C important questions
 
Here is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docxHere is the grading matrix where the TA will leave feedback. If you .docx
Here is the grading matrix where the TA will leave feedback. If you .docx
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1
 
Python
PythonPython
Python
 
computer programming and utilization
computer programming and utilizationcomputer programming and utilization
computer programming and utilization
 
GE3151_PSPP_UNIT_3_Notes
GE3151_PSPP_UNIT_3_NotesGE3151_PSPP_UNIT_3_Notes
GE3151_PSPP_UNIT_3_Notes
 

More from Elsayed Hemayed

14 cie552 camera_calibration
14 cie552 camera_calibration14 cie552 camera_calibration
14 cie552 camera_calibration
Elsayed Hemayed
 
12 cie552 object_recognition
12 cie552 object_recognition12 cie552 object_recognition
12 cie552 object_recognition
Elsayed Hemayed
 
11 cie552 image_featuresii_sift
11 cie552 image_featuresii_sift11 cie552 image_featuresii_sift
11 cie552 image_featuresii_sift
Elsayed Hemayed
 
10 cie552 image_featuresii_corner
10 cie552 image_featuresii_corner10 cie552 image_featuresii_corner
10 cie552 image_featuresii_corner
Elsayed Hemayed
 
09 cie552 image_featuresi
09 cie552 image_featuresi09 cie552 image_featuresi
09 cie552 image_featuresi
Elsayed Hemayed
 
08 cie552 image_segmentation
08 cie552 image_segmentation08 cie552 image_segmentation
08 cie552 image_segmentation
Elsayed Hemayed
 
07 cie552 image_mosaicing
07 cie552 image_mosaicing07 cie552 image_mosaicing
07 cie552 image_mosaicing
Elsayed Hemayed
 
06 cie552 image_manipulation
06 cie552 image_manipulation06 cie552 image_manipulation
06 cie552 image_manipulation
Elsayed Hemayed
 
05 cie552 image_enhancement
05 cie552 image_enhancement05 cie552 image_enhancement
05 cie552 image_enhancement
Elsayed Hemayed
 
04 cie552 image_filtering_frequency
04 cie552 image_filtering_frequency04 cie552 image_filtering_frequency
04 cie552 image_filtering_frequency
Elsayed Hemayed
 
03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatial03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatial
Elsayed Hemayed
 
02 cie552 image_andcamera
02 cie552 image_andcamera02 cie552 image_andcamera
02 cie552 image_andcamera
Elsayed Hemayed
 
01 cie552 introduction
01 cie552 introduction01 cie552 introduction
01 cie552 introduction
Elsayed Hemayed
 
Csci101 lect10 algorithms_iii
Csci101 lect10 algorithms_iiiCsci101 lect10 algorithms_iii
Csci101 lect10 algorithms_iii
Elsayed Hemayed
 
Csci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeCsci101 lect09 vectorized_code
Csci101 lect09 vectorized_code
Elsayed Hemayed
 
Csci101 lect08b matlab_programs
Csci101 lect08b matlab_programsCsci101 lect08b matlab_programs
Csci101 lect08b matlab_programs
Elsayed Hemayed
 
Csci101 lect07 algorithms_ii
Csci101 lect07 algorithms_iiCsci101 lect07 algorithms_ii
Csci101 lect07 algorithms_ii
Elsayed Hemayed
 
Csci101 lect06 advanced_looping
Csci101 lect06 advanced_loopingCsci101 lect06 advanced_looping
Csci101 lect06 advanced_looping
Elsayed Hemayed
 
Csci101 lect05 formatted_output
Csci101 lect05 formatted_outputCsci101 lect05 formatted_output
Csci101 lect05 formatted_output
Elsayed Hemayed
 
Csci101 lect01 first_program
Csci101 lect01 first_programCsci101 lect01 first_program
Csci101 lect01 first_program
Elsayed Hemayed
 

More from Elsayed Hemayed (20)

14 cie552 camera_calibration
14 cie552 camera_calibration14 cie552 camera_calibration
14 cie552 camera_calibration
 
12 cie552 object_recognition
12 cie552 object_recognition12 cie552 object_recognition
12 cie552 object_recognition
 
11 cie552 image_featuresii_sift
11 cie552 image_featuresii_sift11 cie552 image_featuresii_sift
11 cie552 image_featuresii_sift
 
10 cie552 image_featuresii_corner
10 cie552 image_featuresii_corner10 cie552 image_featuresii_corner
10 cie552 image_featuresii_corner
 
09 cie552 image_featuresi
09 cie552 image_featuresi09 cie552 image_featuresi
09 cie552 image_featuresi
 
08 cie552 image_segmentation
08 cie552 image_segmentation08 cie552 image_segmentation
08 cie552 image_segmentation
 
07 cie552 image_mosaicing
07 cie552 image_mosaicing07 cie552 image_mosaicing
07 cie552 image_mosaicing
 
06 cie552 image_manipulation
06 cie552 image_manipulation06 cie552 image_manipulation
06 cie552 image_manipulation
 
05 cie552 image_enhancement
05 cie552 image_enhancement05 cie552 image_enhancement
05 cie552 image_enhancement
 
04 cie552 image_filtering_frequency
04 cie552 image_filtering_frequency04 cie552 image_filtering_frequency
04 cie552 image_filtering_frequency
 
03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatial03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatial
 
02 cie552 image_andcamera
02 cie552 image_andcamera02 cie552 image_andcamera
02 cie552 image_andcamera
 
01 cie552 introduction
01 cie552 introduction01 cie552 introduction
01 cie552 introduction
 
Csci101 lect10 algorithms_iii
Csci101 lect10 algorithms_iiiCsci101 lect10 algorithms_iii
Csci101 lect10 algorithms_iii
 
Csci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeCsci101 lect09 vectorized_code
Csci101 lect09 vectorized_code
 
Csci101 lect08b matlab_programs
Csci101 lect08b matlab_programsCsci101 lect08b matlab_programs
Csci101 lect08b matlab_programs
 
Csci101 lect07 algorithms_ii
Csci101 lect07 algorithms_iiCsci101 lect07 algorithms_ii
Csci101 lect07 algorithms_ii
 
Csci101 lect06 advanced_looping
Csci101 lect06 advanced_loopingCsci101 lect06 advanced_looping
Csci101 lect06 advanced_looping
 
Csci101 lect05 formatted_output
Csci101 lect05 formatted_outputCsci101 lect05 formatted_output
Csci101 lect05 formatted_output
 
Csci101 lect01 first_program
Csci101 lect01 first_programCsci101 lect01 first_program
Csci101 lect01 first_program
 

Recently uploaded

How to Create a Stage or a Pipeline in Odoo 17 CRM
How to Create a Stage or a Pipeline in Odoo 17 CRMHow to Create a Stage or a Pipeline in Odoo 17 CRM
How to Create a Stage or a Pipeline in Odoo 17 CRM
Celine George
 
Post init hook in the odoo 17 ERP Module
Post init hook in the  odoo 17 ERP ModulePost init hook in the  odoo 17 ERP Module
Post init hook in the odoo 17 ERP Module
Celine George
 
8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity
RuchiRathor2
 
A Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by QuizzitoA Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by Quizzito
Quizzito The Quiz Society of Gargi College
 
What are the new features in the Fleet Odoo 17
What are the new features in the Fleet Odoo 17What are the new features in the Fleet Odoo 17
What are the new features in the Fleet Odoo 17
Celine George
 
pol sci Election and Representation Class 11 Notes.pdf
pol sci Election and Representation Class 11 Notes.pdfpol sci Election and Representation Class 11 Notes.pdf
pol sci Election and Representation Class 11 Notes.pdf
BiplabHalder13
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ShwetaGawande8
 
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Kalna College
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
Kalna College
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Quiz Club IIT Kanpur
 
220711130095 Tanu Pandey message currency, communication speed & control EPC ...
220711130095 Tanu Pandey message currency, communication speed & control EPC ...220711130095 Tanu Pandey message currency, communication speed & control EPC ...
220711130095 Tanu Pandey message currency, communication speed & control EPC ...
Kalna College
 
How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17
Celine George
 
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
biruktesfaye27
 
How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...
Infosec
 
Non-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech ProfessionalsNon-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech Professionals
MattVassar1
 
Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
PJ Caposey
 
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
Nguyen Thanh Tu Collection
 
Creating Images and Videos through AI.pptx
Creating Images and Videos through AI.pptxCreating Images and Videos through AI.pptx
Creating Images and Videos through AI.pptx
Forum of Blended Learning
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

How to Create a Stage or a Pipeline in Odoo 17 CRM
How to Create a Stage or a Pipeline in Odoo 17 CRMHow to Create a Stage or a Pipeline in Odoo 17 CRM
How to Create a Stage or a Pipeline in Odoo 17 CRM
 
Post init hook in the odoo 17 ERP Module
Post init hook in the  odoo 17 ERP ModulePost init hook in the  odoo 17 ERP Module
Post init hook in the odoo 17 ERP Module
 
8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity
 
A Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by QuizzitoA Quiz on Drug Abuse Awareness by Quizzito
A Quiz on Drug Abuse Awareness by Quizzito
 
What are the new features in the Fleet Odoo 17
What are the new features in the Fleet Odoo 17What are the new features in the Fleet Odoo 17
What are the new features in the Fleet Odoo 17
 
pol sci Election and Representation Class 11 Notes.pdf
pol sci Election and Representation Class 11 Notes.pdfpol sci Election and Representation Class 11 Notes.pdf
pol sci Election and Representation Class 11 Notes.pdf
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
 
Contiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptxContiguity Of Various Message Forms - Rupam Chandra.pptx
Contiguity Of Various Message Forms - Rupam Chandra.pptx
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
 
220711130095 Tanu Pandey message currency, communication speed & control EPC ...
220711130095 Tanu Pandey message currency, communication speed & control EPC ...220711130095 Tanu Pandey message currency, communication speed & control EPC ...
220711130095 Tanu Pandey message currency, communication speed & control EPC ...
 
How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17
 
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
 
How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...How to stay relevant as a cyber professional: Skills, trends and career paths...
How to stay relevant as a cyber professional: Skills, trends and career paths...
 
Non-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech ProfessionalsNon-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech Professionals
 
Keynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse CityKeynote given on June 24 for MASSP at Grand Traverse City
Keynote given on June 24 for MASSP at Grand Traverse City
 
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
 
Creating Images and Videos through AI.pptx
Creating Images and Videos through AI.pptxCreating Images and Videos through AI.pptx
Creating Images and Videos through AI.pptx
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptx
 

Csci101 lect02 selection_andlooping

  • 1. CSCI 101 Selection and Looping Program control, if-else, logical expressions, for loop
  • 2. Overview • Review • Program control • if-else statement – Relational and logical operators – Logical expressions • for loop statement
  • 3. How to write a program? 1. Read the problem statement, and identify – The input and its range – The output – The relationship between the input and the output (how to compute the output) [Comprehend] 2. Write your thoughts as a sequence of steps. [Algorithm] 3. Convert these steps to Code. [Program] 4. Test your code and compare your program result against a human result. [Testing]
  • 4. Calculate area of a rectangle (Algorithm  Program) 1. Get height h  h=input(‘enter height: ’); 2. Get width w  w=input(‘enter width: ’); 3. Calculate area = h * w  area = h * w; 4. Display area  disp (area);
  • 5. Program Control • How to control the flow of the program? – To executes some statements and not the other based on the input data. – To make the program takes decision • How to make some statements executed several times.
  • 6. Print the maximum of two numbers (Algorithm and Program) 1. Get number1 as X  X=input(‘enter num1:’); 2. Get number2 as Y  Y=input(‘enter num2:’); 3. If X > Y  if X>Y display X disp(X); Otherwise else display Y disp(Y); end
  • 7. Print the maximum of two numbers (Program and Testing) % printmax.m X=input(‘enter num1:’); Y=input(‘enter num2:’); if X>Y disp(X); else disp(Y); end >>printmax enter num1: 5 enter num2: 10 10 >>printmax enter num1: 8 enter num2: 3 8 5 10 X Y 8 3
  • 8. Print two number in ascending order (Algorithm  Program) 1. Get number1 as X  X=input(‘enter num1:’); 2. Get number2 as Y  Y=input(‘enter num2:’); 3. If X > Y  if X>Y display Y, X disp(Y); disp(X); Otherwise else display X, Y disp(X); disp(Y); end
  • 9. Print two number in ascending order (Program and Testing) % order2.m X=input(‘enter num1:’); Y=input(‘enter num2:’); if X>Y disp(Y); disp(X); else disp(X); disp(Y); end >>order2 enter num1: 5 enter num2: 10 5 10 >>order2 enter num1: 8 enter num2: 3 3 8 5 10 X Y 8 3
  • 10. If-else statement if condition % do this part if condition is true else %do this part if the condition is false end Condition (use relational operators): >, <, >=, <=, ==, ~=
  • 11. Relational Operators • Relational operators test the Relationship between two operands (which can be expressions) • They are a “Truth Statement”, and resolve to either True (1) or False (0) Operator Operation == Equal to ~= Not equal to > Greater than >= Greater than or equal to < Less than <= Less than or equal to
  • 12. Logical Operators • Relational operators are binary operators so they can have only two operands • To have a more complicated condition, we need to use logical operators • Logic Operators can combine “truth statements” together in helpful ways. (and, or, not) Inputs and or not A B A && B A || B ~A false false false false true false true false true true true false false true false true true true true false
  • 13. Logical Expressions Examples Write the if condition for the following cases: 1. Check if x > y > z  if x>y && y>z 2. Check if x is greater than y or less than or equal to z  if x>y || x <=z 3. Check if x does not equal y but equal z  if x~=y && x==z 4. Check if x is even  if rem(x,2)==0
  • 14. X=input(‘enter num1:’); Y=input(‘enter num2:’); if X>Y disp(X); else disp(Y); end Repeat a program N times for i=1:1:5 end Iteration counter First counter value Step value Last counter value
  • 15. Try it in MATLAB for i=1:1:5 X=input(‘enter num1:’); Y=input(‘enter num2:’); if X>Y disp(X); else disp(Y); end end X Y i How many times these loops will run: for i=1:2:10 for z=10:2:20 for a=10:-2:1 for x=1:10 ?
  • 16. Calculate sum from 1 to N (Program) N=input(‘enter a number:’); sum=0; for i=1:N sum=sum+i; end disp(sum); How to sum only even numbers? N i sum 5 0 1 1 2 3 3 6 4 10 5 15
  • 17. Calculate factorial of a number N (Program) N=input(‘enter a number:’); f=1; for i=1:N f=f*i; end disp(f); N i f 5 1 1 1 2 2 3 6 4 24 5 120
  • 18. What this program does? N=input(‘enter a number:’); sum=0; for i=1:N x=input(‘enter a value:’); sum=sum+x; end disp(sum); N i x sum 5 0 1 3 3 2 5 8 3 0 8 4 -2 6 5 1 7 How to compute the average of N numbers?
  • 19. Sum only positive numbers? N=input(‘enter a number:’); sum=0; for i=1:N x=input(‘enter a value:’); if x>0 sum=sum+x; end end disp(sum); N i x sum 5 0 1 3 3 2 5 8 3 -3 8 4 -2 8 5 1 9
  • 20. Sum and Average positive numbers? N=input(‘enter a number:’); sum=0; c=0; for i=1:N x=input(‘enter a value:’); if x>0 sum=sum+x; c=c+1; end End Avg=sum/c; disp(sum); Disp(Avg); N i x sum c 5 0 0 1 3 3 1 2 5 8 2 3 -3 8 2 4 -2 8 2 5 1 9 3 C is used to count positive numbers
  翻译: