SlideShare a Scribd company logo
1 of 24
1-IF then Logic in C#
EHSAN EHRARI
Operators
 Operators in C # are special symbols that specify what operations to perform on
operands.
 C # has different operators that have different meanings depending on the data of
the types of operands.
 C # operators usually have one or two operands. Operators that have an operand
are called unit operators.
Operators table
Truth table
What is IF Logic?
 An if statement is a programming conditional statement that, if
proved true, performs a function or displays information
 They work with variables
 They can only be inside methods
 Can’t declare outside of the methods inside the class
 a general example of an if statement, not specific to any
particular programming language.
Challenge!
Name some IF conditions on
video games?
Problem
 In the state of Herat where we live, The driving age is 7
 Make a program to check if you are eligible to drive!
 And if you were eligible print out “Hey You Are Eligible”
Solution 1
Solution 2
Else statement
 If condition returns true then the statements inside the body of “if” are executed
and the statements inside body of “else” are skipped.
If condition returns false then the statements inside the body of “if” are skipped
and the statements in “else” are executed.
Problem
 In the state of Herat where we live, The driving age is 7
 Make a program to check if you are eligible to drive!
 And if you were eligible print out “Hey You Are Eligible”
 And If you were not eligible print out “You can’t drive”
Solution
Input Manager
 The Input Manager window allows you to define input axes and their associated
actions for your Project. To access it, from Unity’s main menu, go to Edit >
Project Settings, then select the Input category.
Example
Input.GetKey
 Input.GetKey
 public static bool GetKey(string name);
 Returns true while the user holds down the key identified by name.
Input.GetKeyDown
 Input.GetKeyDown
 public static bool GetKeyDown(string name);
 Returns true while the user holds down the key identified by name.
Input.GetKeyUp
 Input.GetKeyUp
 public static bool GetKeyUp(string name);
 Returns true during the frame the user releases the key identified by name.
KeyCode
 Key codes returned by Event.keyCode. These map directly to a physical key on
the keyboard.
 KeyCode.Space
 KeyCode.A
 KeyCode.Enter
 Keycode.P
SerializeField
 When you want a private member to be visible in inspector we use SerializeField
//because it has the SerializeField attribute applied.
[SerializeField]
private bool hasHealthPotion = true;
Challenge!
 Make a program to collect points every time the user presses space key.
 Points should be visible only to player and also in the inspector
Challenge!
 Make a program to collect points every time the user presses space key.
 Points should be visible only to player and also in the inspector
 If points are greater than or equal to 50 then print “You are awesome”
Challenge!
 Make a program to collect points every time the user presses space key.
 Points should be visible only to player and also in the inspector
 If points are greater than or equal to 50 then print “You are awesome”
 Make a condition to print “You are awesome” only once
 Check if we have printed the text don’t do it again
Homework!
1. Write a C# Sharp program to read the age of a candidate and determine whether
it is eligible for casting his/her own vote.
1. Test Data : 21
Expected Output:
Congratulation! You are eligible for casting your vote.
2. Write a C# Sharp program to check whether a given number is positive or
negative.
1. Test Data : 14
Expected Output :
14 is a positive number
Want more resources!
 https://www.programiz.com/csharp-programming/if-else-statement
 https://www.w3schools.com/cs/cs_conditions.asp
 https://www.tutorialsteacher.com/csharp/csharp-ternary-operator
 https://www.tutorialspoint.com/csharp/csharp_operators.htm
 https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/
 https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/if-
else

More Related Content

What's hot (20)

Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
 
Loops c++
Loops c++Loops c++
Loops c++
 
for loop in java
for loop in java for loop in java
for loop in java
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Control structure
Control structureControl structure
Control structure
 
C if else
C if elseC if else
C if else
 
Control structures i
Control structures i Control structures i
Control structures i
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Loops in c
Loops in cLoops in c
Loops in c
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
 
Break and continue
Break and continueBreak and continue
Break and continue
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
 

Similar to IF Else logic in c#

Similar to IF Else logic in c# (20)

Manual Testing.
Manual Testing.Manual Testing.
Manual Testing.
 
Software Testing Introduction (Part 1)
Software Testing Introduction (Part 1)Software Testing Introduction (Part 1)
Software Testing Introduction (Part 1)
 
Unit1
Unit1Unit1
Unit1
 
Chapter 2- Prog101.ppt
Chapter 2- Prog101.pptChapter 2- Prog101.ppt
Chapter 2- Prog101.ppt
 
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1ILearn Programming with Livecoding.tv http://goo.gl/tIgO1I
Learn Programming with Livecoding.tv http://goo.gl/tIgO1I
 
Fundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptxFundamentals of Programming Lecture #1.pptx
Fundamentals of Programming Lecture #1.pptx
 
programming.ppt
programming.pptprogramming.ppt
programming.ppt
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
 
H testing and debugging
H testing and debuggingH testing and debugging
H testing and debugging
 
1.4 conditions and loops
1.4   conditions and loops1.4   conditions and loops
1.4 conditions and loops
 
Testing concepts ppt
Testing concepts pptTesting concepts ppt
Testing concepts ppt
 
Testing concepts ppt
Testing concepts pptTesting concepts ppt
Testing concepts ppt
 
Programming
ProgrammingProgramming
Programming
 
Mastering python lesson2
Mastering python lesson2Mastering python lesson2
Mastering python lesson2
 
Decision control
Decision controlDecision control
Decision control
 
jhtp9_ch04.ppt
jhtp9_ch04.pptjhtp9_ch04.ppt
jhtp9_ch04.ppt
 
Amcat Employability Test Report
Amcat Employability Test ReportAmcat Employability Test Report
Amcat Employability Test Report
 
Talk or Not to Talk @ CSCW 2012
Talk or Not to Talk @ CSCW 2012Talk or Not to Talk @ CSCW 2012
Talk or Not to Talk @ CSCW 2012
 
SWQ
SWQSWQ
SWQ
 

Recently uploaded

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 

IF Else logic in c#

  • 1. 1-IF then Logic in C# EHSAN EHRARI
  • 2. Operators  Operators in C # are special symbols that specify what operations to perform on operands.  C # has different operators that have different meanings depending on the data of the types of operands.  C # operators usually have one or two operands. Operators that have an operand are called unit operators.
  • 5. What is IF Logic?  An if statement is a programming conditional statement that, if proved true, performs a function or displays information  They work with variables  They can only be inside methods  Can’t declare outside of the methods inside the class  a general example of an if statement, not specific to any particular programming language.
  • 6. Challenge! Name some IF conditions on video games?
  • 7. Problem  In the state of Herat where we live, The driving age is 7  Make a program to check if you are eligible to drive!  And if you were eligible print out “Hey You Are Eligible”
  • 10. Else statement  If condition returns true then the statements inside the body of “if” are executed and the statements inside body of “else” are skipped. If condition returns false then the statements inside the body of “if” are skipped and the statements in “else” are executed.
  • 11. Problem  In the state of Herat where we live, The driving age is 7  Make a program to check if you are eligible to drive!  And if you were eligible print out “Hey You Are Eligible”  And If you were not eligible print out “You can’t drive”
  • 13. Input Manager  The Input Manager window allows you to define input axes and their associated actions for your Project. To access it, from Unity’s main menu, go to Edit > Project Settings, then select the Input category.
  • 15. Input.GetKey  Input.GetKey  public static bool GetKey(string name);  Returns true while the user holds down the key identified by name.
  • 16. Input.GetKeyDown  Input.GetKeyDown  public static bool GetKeyDown(string name);  Returns true while the user holds down the key identified by name.
  • 17. Input.GetKeyUp  Input.GetKeyUp  public static bool GetKeyUp(string name);  Returns true during the frame the user releases the key identified by name.
  • 18. KeyCode  Key codes returned by Event.keyCode. These map directly to a physical key on the keyboard.  KeyCode.Space  KeyCode.A  KeyCode.Enter  Keycode.P
  • 19. SerializeField  When you want a private member to be visible in inspector we use SerializeField //because it has the SerializeField attribute applied. [SerializeField] private bool hasHealthPotion = true;
  • 20. Challenge!  Make a program to collect points every time the user presses space key.  Points should be visible only to player and also in the inspector
  • 21. Challenge!  Make a program to collect points every time the user presses space key.  Points should be visible only to player and also in the inspector  If points are greater than or equal to 50 then print “You are awesome”
  • 22. Challenge!  Make a program to collect points every time the user presses space key.  Points should be visible only to player and also in the inspector  If points are greater than or equal to 50 then print “You are awesome”  Make a condition to print “You are awesome” only once  Check if we have printed the text don’t do it again
  • 23. Homework! 1. Write a C# Sharp program to read the age of a candidate and determine whether it is eligible for casting his/her own vote. 1. Test Data : 21 Expected Output: Congratulation! You are eligible for casting your vote. 2. Write a C# Sharp program to check whether a given number is positive or negative. 1. Test Data : 14 Expected Output : 14 is a positive number
  • 24. Want more resources!  https://www.programiz.com/csharp-programming/if-else-statement  https://www.w3schools.com/cs/cs_conditions.asp  https://www.tutorialsteacher.com/csharp/csharp-ternary-operator  https://www.tutorialspoint.com/csharp/csharp_operators.htm  https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/  https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/if- else