Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

CONTROL

STRUCTURES
CS115C - COMPUTER PROGRAMMING
TOPIC OUTLINE

Decision Control Structures

Repetition Control Structures

Branching Statements

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 2


OBJECTIVES
• Use decision control structures (if, else, switch) which allows
selection of specific sections of code to be executed
• Use repetition control structures (while, do-while, for) which
allow executing specific sections of code several times
• Use branching statements (break, continue, return) which
allows redirection of program flow

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 3


Decision Control
Structures
Decision control structures are C# statements that allows us to
select and execute specific blocks of code while skipping other
sections

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 4


if statement
The if-statement specifies that a statement (or block of code) will be
executed if and only if a certain Boolean statement is true

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 5


if statement

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 6


if statement

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 7


If-else statement
• The if-else statement is
used when we want to
execute a certain statement
if a condition is true, and a
different statement if the
condition is false.

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 8


If-else statement

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 9


If-else statement

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 10


If-else-if statement
• The statement in the else-clause of an if-else block can be
another if-else structures.
• This cascading of structures allows us to make more
complex selections.

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 11


If-else-if statement

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 12


If-else-if statement

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 13


If-else-else-if statement

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 14


COMMON ERRORS

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 15


COMMON ERRORS

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 16


LET US TRY
10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 17
NUMBER IN WORDS
• Get a number as input from the user, and output the
equivalent of the number in words. The number
inputted should range from 1-10. If the user inputs a
number that is not in the range, output, "Invalid
number".

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 18


10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 19
ARITHMETIC
Write a C# program that will
allow user to choose from the
following options; if the user
selects
• 1 calculate the sum of two
numbers,
• 2 calculate the difference
• 3 calculate the product
• 4 exit the Environment using this:
Environment.Exit(0)
Output INVALID NUMBER! that is
not in range
10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 20
Join our online GDB online Compiler
https://www.onlinegdb.com/
https://bit.ly/2BSeCEA

10/3/2022 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 21

You might also like