0% found this document useful (0 votes)
58 views13 pages

C# Control Statements Overview

The document discusses various conditional statements in C#, including if statements, if-else if statements, nested if statements, and switch statements. It provides examples of each. The lecture also reviews operators, assignment operators, and asks students to code a program to check eligibility. References for further reading are provided at the end.

Uploaded by

ishtiaq mushtaq
Copyright
© © All Rights Reserved
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

Topics covered

  • C# programming community,
  • C# programming techniques,
  • C# programming statements,
  • programming references,
  • C# programming fundamentals,
  • C# programming skills,
  • grade evaluation,
  • decision making,
  • C# programming logic,
  • C# programming methodologies
0% found this document useful (0 votes)
58 views13 pages

C# Control Statements Overview

The document discusses various conditional statements in C#, including if statements, if-else if statements, nested if statements, and switch statements. It provides examples of each. The lecture also reviews operators, assignment operators, and asks students to code a program to check eligibility. References for further reading are provided at the end.

Uploaded by

ishtiaq mushtaq
Copyright
© © All Rights Reserved
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

Topics covered

  • C# programming community,
  • C# programming techniques,
  • C# programming statements,
  • programming references,
  • C# programming fundamentals,
  • C# programming skills,
  • grade evaluation,
  • decision making,
  • C# programming logic,
  • C# programming methodologies

Emerging Technologies (IT-3302)

Week 03

Usman Akbar
[Link]@[Link]
FB Group - SuperiorUniversity2016
Lecture Content

 Last lecture review


 C# - if Statement & if- else if
 C# - Nested if Statements
 C# - Switch Statement
 Tasks & Questions
 References

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 2


Last Lecture Review

An operator is a symbol that tells the compiler to perform specific


mathematical or logical manipulations. C# has rich set of built-in
operators and provides the following type of operators

 Arithmetic Operators
 + - * / % ++ --

 Relational Operators
 == != > < >= <=

 Logical Operators
 && || !
 Assignment Operators
 = += -= *= /=

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 3


C# - if Statement

 An if statement consists of a boolean expression followed by one or


more statements.

if(boolean_expression)
{
/* statement(s) will execute if the boolean expression is
true */
}

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 4


Example
using System;
namespace DecisionMaking {
class Program {
static void Main(string[] args) {
/* local variable definition */
int a = 10;
/* check the boolean condition using if statement
*/
if (a < 20) {
/* if condition is true then print the following */
[Link]("a is less than 20");
}
[Link]("value of a is : {0}", a);
[Link](); } }
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 5
C# if...else if (if-then-else if) Statement

if (boolean-expression-1)
{
// statements executed if boolean-expression-1 is
true
}
else if (boolean-expression-2)
{
// statements executed if boolean-expression-2 is
true
}
else if (boolean-expression-3)
{
// statements executed if boolean-expression-3 is
true
}

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 6


C# - Nested if Statements

if (boolean-expression-1)
{
// statements executed if boolean-expression-1 is true
??
if (boolean-expression-2)
{
// statements executed if boolean-expression-2 is
true
}
}

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 7


Class Task

Write Console C# Program which can

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 8


C# - Switch Statement

Syntax A switch statement allows a variable to be


switch(expression) { tested for equality against a list of values.
case expression : Each value is called a case, and the
statement(s); variable being switched on is checked for
break; /* optional */ each switch case.
case expression :
statement(s);
break; /* optional */
/* you can have any number of case
statements */
default : /* Optional */
statement(s);
}
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 9
Grades : Example

char grade = 'B';

switch (grade) {
case 'A':
[Link]("Excellent!");
break;
case 'B':
case 'C':
[Link]("Well done");
break;
case 'D':
[Link]("You passed");
break;
case 'F':
[Link]("Better try again");
break;
default:
[Link]("Invalid grade");
break;
EMERGING TECHNOLOGIES ( USMAN AKBAR ) 10
There are following assignment operators supported by C#

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 11


Question

Questions….?
References

 C# 6 for Programmers ( Chapter 03 )


 [Link]
 [Link]

Social Community Help ….!


 [Link]
 [Link]
 [Link]

EMERGING TECHNOLOGIES ( USMAN AKBAR ) 13

You might also like