Conditional Statements Group Report.pptx NEW 5
Conditional Statements Group Report.pptx NEW 5
Information Technology
LESSON 1
PREPARED BY:
BALLER, JOHN HENRY V.
CABIGAN, MJ R.
DIGMAN, MA. LOVINIA B.
GALON, LERITA JOY O.
LAGUARTILLA JR., VIRGILIO E.
MAGNAY, RHEA LYN B.
PAMPILLONA, TRISTAN T.
PEREZ, NHAZ D.
TOQUERO, JACOB ZACH R .
Department of Industrial and
Information Technology
GROUP4
PRESENTATION
Department of Industrial and
Information Technology
TOPIC
Vl. Conditional • What is a Statement?
Statements • Types of Statement
a. Declaration Statement
b. Expression Statement
c. Control Flow Statement
i. Conditional
ii. Repetition
Department of Industrial and
Information Technology
TOPIC
• A Block Statement
The Conditional Statement
a. If statement
b. If Else statement
c. If Else statement
d. Switch Statement
e. Nested Conditional Statement
Department of Industrial and
Information Technology
TOPIC
Vll. Repetition • The for Statement
Statements a. Initialization
b. Condition Expression
c. Expression List
Department of Industrial and
Information Technology
TOPIC
• The while statement
The do-while statement
The for-each statement
The break statement
The continue statement
The empty statement
Department of Industrial and
Information Technology
Conditional Statements
• A statement that can be executed based on a condition is
known as a “Conditional Statement”. The statement is
often a block of code.
Department of Industrial and
Information Technology
What is a Statement?
• A statement is a single line of code that performs an
action or expresses a command.
• The actions that a program takes are expressed in
statements. Common actions include declaring variables,
assigning values, calling methods, looping through
collections, and branching to one or another block of
code, depending on a given condition.
Department of Industrial and
Information Technology
Exp:
Department of Industrial and
Information Technology
Types of Statements
Declaration Statement
Expression Statement
Control Flow Statement
Department of Industrial and
Information Technology
Declaration Statement
• Declaration statements are used to declare and initialize variables.
• The following code shows examples of variable declarations with and
without an initial assignment, and a constant declaration with the
necessary initialization.
Exp:
Department of Industrial and
Information Technology
Expression Statement
• An expression followed by a semicolon is called an expression statement.
• The following code shows examples of expression statements, including
assignment, object creation with assignment, and method invocation.
Exp:
Department of Industrial and
Information Technology
Conditional
• Used to make decisions in the code based on certain
conditions
Types of Conditional Statements:
•If statement
•Else statement
•Else if statement
•Switch statement
Department of Industrial and
Information Technology
Repetition
Repetition statements are called loops, and are used to repeat
the same code mulitple times in succession.
The number of repetitions is based on criteria defined in the loop
structure, usually a true/false expression.
Department of Industrial and
Information Technology
Exp:
Department of Industrial and
Information Technology
BLOCK STATEMENT
A block is a combination of zero
or more statements that is
enclosed inside curly brackets
{ }.
Department of Industrial and
Information Technology
CONDITIONAL STATEMENT
Conditional statements in are used to make decisions in your code based
on certain conditions or expressions. These statements allow you to
control the flow of your program by executing different blocks of code
depending on whether a condition is true or false.
Department of Industrial and
Information Technology
• IF STATEMENT
a. if statement is a control
structure used to execute a
block of code conditionally. It
allows you to specify a
condition, and if that condition
evaluates to true, the code
block within the "if" statement
is executed.
Department of Industrial and
Information Technology
• IF - ELSE STATEMENT
b. The if-else statement allows us to
provide an alternative block of code
to execute if the condition is false. An
if-else statement in C# is a control
structure that allows you to
conditionally execute different blocks
of code based on a specified
condition. It is used to make decisions
in your program based on whether a
particular condition is true or false.
Department of Industrial and
Information Technology
• IF - ELSE - IF STATEMENT
c. In C#, an "if-else-if" statement is a
control structure that allows you to
execute different blocks of code
based on multiple conditions. It
provides a way to test multiple
conditions sequentially and perform
different actions depending on the
outcome of each condition.
Department of Industrial and
Information Technology
• SWITCH STATEMENT
d. A switch statement executes the
statement list in the first switch section
whose case pattern matches a match
expression and whose case guard, if
present, evaluates to true. A switch
statement evaluates case patterns in text
order from top to bottom. The compiler
generates an error when a switch statement
contains an unreachable case. That is a case
that is already handled by an upper case or
whose pattern is impossible to match.
Department of Industrial and
Information Technology
Department of Industrial and
Information Technology
EXP: Output:
Department of Industrial and
Information Technology
• NESTED CONDITIONAL
STATEMENT
e. The nested if statement in C#
refers to the concept of having one
if statement inside another if
statement. It allows for more
complex decision-making logic by
evaluating multiple conditions in a
hierarchical manner.
Department of Industrial and
Information Technology
Exp:
Department of Industrial and
Information Technology
REPETITION STATEMENT
- allow a block of code to be executed multiple times based on a
condition.
Department of Industrial and
Information Technology
A. Initialization
-Initialization sets the variable to a new instance. It must be to a type that is
compatible with the declaration type.
Example:
Department of Industrial and
Information Technology
b. CONDITION EXPRESSION
This is the condition that must be true for the loop to continue executing.
Example:
c. EXPRESSION LIST
-This is executed after each iteration of the loop, often used to update the loop
counter
Example:
Department of Industrial and
Information Technology
• AN EMPTY STATEMENT
The empty statement consists
of a single semicolon. It does
nothing and can be used in
places where a statement is
required but no action needs to
be performed.
Department of Industrial and
Information Technology
QUIZ
1. What is a statement in programming?
A. A command that performs an action
B.A type of variable
B. A function that returns a value
D. A comment in the code
2. Which of the following is used to make decisions in the code based on certain conditions?
A. Declaration Statement
B. Expression Statement
C. Control Flow Statement
D Conditional Statement
Department of Industrial and
Information Technology
3. (True or False): All programming languages have the same syntax for conditional
statements.
7. What keyword is used to define a block of code that executes when a condition is true?
A. else
B. if
C. switch
D. case
Department of Industrial and
Information Technology
A. Greater
B. Lesser
C. Error
D. None
Department of Industrial and
Information Technology
11. Which of the following statements is used to exit a loop or switch statement?
A. break
B. continue
C. return
D. exit
12. What is the result of the following expression: true && false?
A. true
B. false
C. null
D. undefined
Department of Industrial and
Information Technology
REFERENCES:
https://www.w3schools.com/
https://www.programiz.com/csharp-programming/expressions-statements-blocks#:~:text=A%20statement%20is%20a%20basic,both%20lines%20above%20are%20statements.
https://www.scaler.com/topics/csharp/control-statements-in-csharp/
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/statements
https://www.geeksforgeeks.org/loops-in-c-sharp/
https://www.programiz.com/csharp-programming/expressions-statements-blocks#:~:text=C%23%20Blocks,enclosed%20inside%20curly%20brackets%20%7B%20%7D.
https://www.scholarhat.com/tutorial/csharp/conditional-statements-in-csharp
https://www.informit.com/articles/article.aspx?p=1701416&seqNum=8
https://www.pluralsight.com/resources/blog/guides/declaring-and-initializing-variables-in-c#:~:text=Initialization%20sets%20the%20variable%20to,compatible%20with%20the
%20declaration%20type.&text=In%20the%20above%20code%2C%20the,achieves%20precisely%20the%20same%20result.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator
https://www.tutorialsteacher.com/csharp/csharp-while-loop
https://www.tutorialsteacher.com/csharp/csharp-do-while-loop
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/jump-statements
Lambda Expressions (C# Programming Guide)
Anonymous Methods (C# Programming Guide)
Action and Func Delegates (C# Programming Guide)
Expression Trees (C# Programming Guide)
The System.Linq.Expressions Namespace
Department of Industrial and
Information Technology
Lambda Expressions in C#
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements/expressions-
operators/lambda-expressions
Anonymous Methods in C#
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements/expressions-
operators/anonymous-methods
Using Delegates in C#
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/delegates
Expression Trees in C#
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/
https://www.c-sharpcorner.com/UploadFile/8af593/conditional-statement-in-C-Sharp/
https://www.youtube.com/watch?v=wxznTygnRfQ
Department of Industrial and
Information Technology
ANSWERS:
1. A
2. D
3. False 10. A
4. B
5. C 11. A
6. B 12. B
7. B 13. A
8. B 14. B
9. A 15. A
Department of Industrial and
Information Technology
THANK YOU!