SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Chapter 5 C# .NET: ConditionalLogic is condition true? false true Processing1 Processing2
Condition logic / Decisions and Branching Recall the problems we solved in week #1 & 2: we used “if (n1 > n2) { … }” to check condition and branch This chapter will cover condition logic in detail
General view if (condition) { // condition is true         // processing1 }  else  { // condition is false      // processing2 } is condition true? false true Processing1 Processing2
Condition if (condition) {      // processing1 }  else  {      // processing2 } - The result must be ‘true’ or ‘false’ ,[object Object]
Eg: For the condition (n1 > n2)  => Is n1 greater than n2?          The result is a ‘true’ or ‘false’
Condition if (condition) {      // processing1 }  else  {      // processing2 } How to set condition? Use operand to compare Eg   (n1 == n2)       (n1 !=  n2)
Condition if (condition) {      // processing1 }  else  {      // processing2 } With more than 1 condition Use  && for “and”: (condition1) && (condition2) Use || for “or”: (condition1) || (condition2) Eg  (n1 >= 0) && (n2 >=0)    => both n1 and n2 must be positive Eg (n1 >= 0) || (n2 >=0)    => either n1 or n2 is positive
condition Comparing Boolean type: boolbuttonClicked = false; if (buttonClicked == true) { … } if ( !buttonClicked) { … }   // not buttonClicked
condition Comparing Char type: char answer = 'N'; if (answer == 'Y') { … }
condition Comparing String type: string input = "";   // empty string if (input == "exit") { … }
condition Comparing String type: string input = "";   // empty string if (input == "exit") { … } String class has methods to do more complex checking such as Compare(), CompareTo(), StartsWith(), EndsWith(), Equals(), etc.  Will cover some in Chapter 9 ,[object Object],                              http://alturl.com/tbwi
Other branching – if only if (condition) { // condition is true         // processing1 }  // No else branch is condition true? false true Processing1
Other branching – if .. Else if .. else is condition1 true? if (condition1) { // condition is true         // processing1 }  else if (condition2) { // condition1 is false and   // condition2 is true      // processing2 } else {// condition1 is false and  //condition2 is false // processing3 } false true is condition2 true? Processing1 false true Processing2 Processing3
Other branching - switch switch (n1) {   case 1:        // processing1        break;  case 2:        // processing2         break;  default:        // processing3       break; } n1 1 2 3 Processing2 Processing3 Processing1
Other branching - switch switch (n1) {   case 1:   case 2:        // processing2         break;  default:        // processing3       break; } n1 1, 2 3 Processing2 Processing3
Other branching - switch switch (n1) {   case 1:        // processing1 goto case 2;  case 2:        // processing2         break;  default:        // processing3       break; } n1 1 2 3 Processing1 Processing2 Processing3
Exercise 5.1 Textbook from page 93 – 98: Part 1  if Statements  Part 2  else ... if in C# .NET
Exercise 5.2 Textbook from page 98 – 106: Part 3  switch Statements in C# .NET  Part 4  C# Operators
Exercise 5.3(a) For the GUI created in Exercise 3.2: Rename all the controls to follow proper naming convention: egtextboxOutput, buttonZero, etc Use winword to draft the pseudo codes for all the button click methods (you may need some variables outside the methods to be accessible by all methods)
Exercise 5.3(b) For the GUI created in Exercise 3.2: Create a new project: Exercise53B Select all the controls in Exercise32 and paste into this new project Code and debug manually by viewing the codes  No worry: we shall use debugging tool to debug this project in chapter 6: Debugging

Weitere ähnliche Inhalte

Was ist angesagt?

Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introductionHock Leng PUAH
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++amber chaudary
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement_jenica
 
Looping statements
Looping statementsLooping statements
Looping statementsJaya Kumari
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppteShikshak
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)heoff
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.comGreen Ecosystem
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 

Was ist angesagt? (18)

C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
 
Lecture 14 - Scope Rules
Lecture 14 - Scope RulesLecture 14 - Scope Rules
Lecture 14 - Scope Rules
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
 
Learn Java Part 2
Learn Java Part 2Learn Java Part 2
Learn Java Part 2
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
 
If-else and switch-case
If-else and switch-caseIf-else and switch-case
If-else and switch-case
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Switch case and looping statement
Switch case and looping statementSwitch case and looping statement
Switch case and looping statement
 
Looping statements
Looping statementsLooping statements
Looping statements
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
Control statements
Control statementsControl statements
Control statements
 

Andere mochten auch

Variables - Value and Reference Type
Variables - Value and Reference TypeVariables - Value and Reference Type
Variables - Value and Reference TypeHock Leng PUAH
 
Objective C Primer (with ref to C#)
Objective C  Primer (with ref to C#)Objective C  Primer (with ref to C#)
Objective C Primer (with ref to C#)Hock Leng PUAH
 
Revision exercises on loop
Revision exercises on loopRevision exercises on loop
Revision exercises on loopHock Leng PUAH
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinFormHock Leng PUAH
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteHock Leng PUAH
 

Andere mochten auch (6)

Variables - Value and Reference Type
Variables - Value and Reference TypeVariables - Value and Reference Type
Variables - Value and Reference Type
 
Objective C Primer (with ref to C#)
Objective C  Primer (with ref to C#)Objective C  Primer (with ref to C#)
Objective C Primer (with ref to C#)
 
Revision exercises on loop
Revision exercises on loopRevision exercises on loop
Revision exercises on loop
 
Spf chapter10 events
Spf chapter10 eventsSpf chapter10 events
Spf chapter10 events
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinForm
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web site
 

Ähnlich wie Spf Chapter5 Conditional Logics

Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Abou Bakr Ashraf
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdfRanjeetaSharma8
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
Conditions In C# C-Sharp
Conditions In C# C-SharpConditions In C# C-Sharp
Conditions In C# C-SharpAbid Kohistani
 
Csphtp1 05
Csphtp1 05Csphtp1 05
Csphtp1 05HUST
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.pptManojKhadilkar1
 
4. programing 101
4. programing 1014. programing 101
4. programing 101IEEE MIU SB
 
Csphtp1 04
Csphtp1 04Csphtp1 04
Csphtp1 04HUST
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2yasir_cesc
 

Ähnlich wie Spf Chapter5 Conditional Logics (20)

Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
1. Control Structure in C.pdf
1. Control Structure in C.pdf1. Control Structure in C.pdf
1. Control Structure in C.pdf
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
Conditions In C# C-Sharp
Conditions In C# C-SharpConditions In C# C-Sharp
Conditions In C# C-Sharp
 
Csphtp1 05
Csphtp1 05Csphtp1 05
Csphtp1 05
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
 
Python for Beginners(v2)
Python for Beginners(v2)Python for Beginners(v2)
Python for Beginners(v2)
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt
 
Loops
LoopsLoops
Loops
 
C # (2)
C # (2)C # (2)
C # (2)
 
C PROGRAMMING p-3.pptx
C PROGRAMMING p-3.pptxC PROGRAMMING p-3.pptx
C PROGRAMMING p-3.pptx
 
BLM101_2.pptx
BLM101_2.pptxBLM101_2.pptx
BLM101_2.pptx
 
4. programing 101
4. programing 1014. programing 101
4. programing 101
 
Csphtp1 04
Csphtp1 04Csphtp1 04
Csphtp1 04
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 

Mehr von Hock Leng PUAH

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image SlideshowHock Leng PUAH
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingHock Leng PUAH
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash fileHock Leng PUAH
 
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthPHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthHock Leng PUAH
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime exampleHock Leng PUAH
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) functionHock Leng PUAH
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleHock Leng PUAH
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common ErrorsHock Leng PUAH
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectHock Leng PUAH
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelHock Leng PUAH
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises GuideHock Leng PUAH
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connectionHock Leng PUAH
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryHock Leng PUAH
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guideHock Leng PUAH
 
Pedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker StudentsPedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker StudentsHock Leng PUAH
 
Do While and While Loop
Do While and While LoopDo While and While Loop
Do While and While LoopHock Leng PUAH
 

Mehr von Hock Leng PUAH (20)

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen Sharing
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash file
 
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthPHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime example
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) function
 
Responsive design
Responsive designResponsive design
Responsive design
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visible
 
Beautiful web pages
Beautiful web pagesBeautiful web pages
Beautiful web pages
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
 
Logic gate lab intro
Logic gate lab introLogic gate lab intro
Logic gate lab intro
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallel
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises Guide
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connection
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guide
 
Nms chapter 01
Nms chapter 01Nms chapter 01
Nms chapter 01
 
Pedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker StudentsPedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker Students
 
Do While and While Loop
Do While and While LoopDo While and While Loop
Do While and While Loop
 

Kürzlich hochgeladen

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 

Kürzlich hochgeladen (20)

Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 

Spf Chapter5 Conditional Logics

  • 1. Chapter 5 C# .NET: ConditionalLogic is condition true? false true Processing1 Processing2
  • 2. Condition logic / Decisions and Branching Recall the problems we solved in week #1 & 2: we used “if (n1 > n2) { … }” to check condition and branch This chapter will cover condition logic in detail
  • 3. General view if (condition) { // condition is true // processing1 } else { // condition is false // processing2 } is condition true? false true Processing1 Processing2
  • 4.
  • 5. Eg: For the condition (n1 > n2) => Is n1 greater than n2? The result is a ‘true’ or ‘false’
  • 6. Condition if (condition) { // processing1 } else { // processing2 } How to set condition? Use operand to compare Eg (n1 == n2) (n1 != n2)
  • 7. Condition if (condition) { // processing1 } else { // processing2 } With more than 1 condition Use && for “and”: (condition1) && (condition2) Use || for “or”: (condition1) || (condition2) Eg (n1 >= 0) && (n2 >=0) => both n1 and n2 must be positive Eg (n1 >= 0) || (n2 >=0) => either n1 or n2 is positive
  • 8. condition Comparing Boolean type: boolbuttonClicked = false; if (buttonClicked == true) { … } if ( !buttonClicked) { … } // not buttonClicked
  • 9. condition Comparing Char type: char answer = 'N'; if (answer == 'Y') { … }
  • 10. condition Comparing String type: string input = ""; // empty string if (input == "exit") { … }
  • 11.
  • 12. Other branching – if only if (condition) { // condition is true // processing1 } // No else branch is condition true? false true Processing1
  • 13. Other branching – if .. Else if .. else is condition1 true? if (condition1) { // condition is true // processing1 } else if (condition2) { // condition1 is false and // condition2 is true // processing2 } else {// condition1 is false and //condition2 is false // processing3 } false true is condition2 true? Processing1 false true Processing2 Processing3
  • 14. Other branching - switch switch (n1) { case 1: // processing1 break; case 2: // processing2 break; default: // processing3 break; } n1 1 2 3 Processing2 Processing3 Processing1
  • 15. Other branching - switch switch (n1) { case 1: case 2: // processing2 break; default: // processing3 break; } n1 1, 2 3 Processing2 Processing3
  • 16. Other branching - switch switch (n1) { case 1: // processing1 goto case 2; case 2: // processing2 break; default: // processing3 break; } n1 1 2 3 Processing1 Processing2 Processing3
  • 17. Exercise 5.1 Textbook from page 93 – 98: Part 1 if Statements Part 2 else ... if in C# .NET
  • 18. Exercise 5.2 Textbook from page 98 – 106: Part 3 switch Statements in C# .NET Part 4 C# Operators
  • 19. Exercise 5.3(a) For the GUI created in Exercise 3.2: Rename all the controls to follow proper naming convention: egtextboxOutput, buttonZero, etc Use winword to draft the pseudo codes for all the button click methods (you may need some variables outside the methods to be accessible by all methods)
  • 20. Exercise 5.3(b) For the GUI created in Exercise 3.2: Create a new project: Exercise53B Select all the controls in Exercise32 and paste into this new project Code and debug manually by viewing the codes No worry: we shall use debugging tool to debug this project in chapter 6: Debugging
  • 21. Summary Condition and operands if .. else if … else switch