This document discusses control structures in computer programming. It outlines topics on decision and repetition control structures and branching statements. The objectives are to use if/else/switch statements for selection, while/do-while/for loops for repetition, and break/continue/return for redirection. The document then explains if, if-else and if-else-if decision statements and provides examples. It also discusses common errors and includes an example problem to solve using control structures.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
17 views21 pages
4 CS115C - Control Structures
This document discusses control structures in computer programming. It outlines topics on decision and repetition control structures and branching statements. The objectives are to use if/else/switch statements for selection, while/do-while/for loops for repetition, and break/continue/return for redirection. The document then explains if, if-else and if-else-if decision statements and provides examples. It also discusses common errors and includes an example problem to solve using control structures.
08/07/2023 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
08/07/2023 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
08/07/2023 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
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 5
if statement
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 6
if statement
08/07/2023 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.
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 8
If-else statement
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 9
If-else statement
08/07/2023 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.
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 11
If-else-if statement
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 12
If-else-if statement
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 13
If-else-else-if statement
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 14
COMMON ERRORS
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 15
COMMON ERRORS
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 16
LET US TRY 08/07/2023 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".
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 18
08/07/2023 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 08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 20 Join our online GDB online Compiler https://www.onlinegdb.com/ https://bit.ly/2BSeCEA
08/07/2023 COLLEGE OF ENGINEERING AND INFORMATION TECHNOLOGY 21