If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.

Slides:



Advertisements
Similar presentations
Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
Advertisements

If Statement. IF Statements Executing code when one thing happens rather than something else is so common in programming that that the IF Statement has.
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Selection Statements Make a decision based on conditions Allows the computer to be intelligent.
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Nested if-else Statements.  Should be indented to make the logic clear.  Nested statement executed only when the branch it is in is executed. For example,
1 Pertemuan 14 PHP: Conditions-loops-functions-Array Last Updated: 23 rd May 2011 By M. Arief
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Lesson 5 - Decision Structure By: Dan Lunney
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 5: Program Logic and Indefinite Loops.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Geography 465 Assignments, Conditionals, and Loops.
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
1 Spreadsheets SELECTION. 2 Aims  Understand the principles of selection in Excel  Examine the basic IF statement format  Look into Nested IF statements.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Application Code PDP PEP public void borrowBook (User user, Book book, Context context) throws PolicyViolationException { Request request = new Request.
Flowcharts! January 13, 2005 These are today’s notes! Do you think we will get more snow?
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
Conditions in Java. First…Boolean Operators A boolean data type is always true or false. Boolean operators always return true or false For example: (x.
Module 3: Steering&Arrays #1 2000/01Scientific Computing in OOCourse code 3C59 Module 3: Algorithm steering elements If, elseif, else Switch and enumerated.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Python Selection. All the programs you have been developing so far have been sequential, this means that each instruction is executed in a set order.
ABSOLUTE VALUE INEQUALITIES.  Just like absolute value equations, inequalities will have two solutions: |3x - 2| ≤ 7 3x – 2 ≤ x ≤ 9 x ≤ 3 -5/3.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Basic Conditions. Challenge: ● Ask the user his/her name ● If it’s “Wally,” jeer him ● Pause video and try on your own.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 3 Decision Trees Conditionals.
Solving and Graphing Inequalities By CaSandra Cowan SMS Math 6-3.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Objects, If, Routines. Creating Objects an object is a fundamental software element that has a state and a set of behaviors. Ex: bank account or student.
AP Computer Science A – Healdsburg High School 1 Unit 7 - Conditional statements - Logical operators in Java - Example.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 4 Making Decisions.
Python Fundamentals: If Statements and Functions Eric Shook Department of Geography Kent State University.
CHAPTER 4 DECISIONS & LOOPS
Chapter 4: Making Decisions.
Selection and Python Syntax
Simple Control Structures
COMP 230 Innovative Education--snaptutorial.com
JavaScript Selection Statement Creating Array
Selection CIS 40 – Introduction to Programming in Python
Using “if” statements.
Counting & Comparing Money 2 $ $ $ $.
Counting & Comparing Money $ $ $ $.
Logical assertions assertion: A statement that is either true or false. Examples: Java was created in The sky is purple. 23 is a prime number. 10.
Selection (IF Statements)
Multiple Selections (ELIF Statements)
Pages:51-59 Section: Control1 : decisions
Logical Operations In Matlab.
Visual Basic – Decision Statements
Conditionals.
A LESSON IN LOOPING What is a loop?
Understanding Conditions
Program Flow.
Relational Operators.
Notes Over 1.7 Solving Inequalities
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Every number has its place!
Notes Over 1.7 Solving Inequalities
Pages:51-59 Section: Control1 : decisions
7.5 Write and Graph Inequalities
Chapter 3: Selection Structures: Making Decisions
Similarities Differences
Inequalities x > a Means x is greater than a
What does this code do? def digitsum(): code goes here def diffsum():
Presentation transcript:

If Statements, Try Catch and Validation

The main statement used in C# for making decisions depending on different conditions is called the If statement. A second useful structure in a similar vein is called Try Catch.

The If Statement If (condition) { ‘execute the code here }

else

Conditions >a > bis a greater than b <a < bis a less than b >=a >= bis a greater than or equal to b <=a <= bis a less than or equal to b ==a == bis a the same as b !=a != bare a and b different

else if

Logical Operators Notice the “and” logical operator & in the Boolean expression. & is one of a range of logical operators that may also be used to evaluate data. “And” may be used should we want to test if a value was greater than one value “And” less than another value. Another useful operator is “Or” indicated by the symbol | In which case you might ask the question is a value one value “Or” another.

Try and Catch

Validation "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." Rich Cook

Validation Systems must be both Robust Responsive

What is Wrong with this? What about those bigger & better idiots?

Testing for a Valid Number

Testing for a Valid Date

Testing for a Blank Field

Testing for Text over a Certain Number of Characters

Validating an Address Question – What is the problem with the above code?

What about the following…

Better…

Better still …