The conditional statement

Slides:



Advertisements
Similar presentations
TSW#3 Solving Compound Inequalities
Advertisements

Decisions with if statements. Simple If Statements if (age < 18) g.drawString(You may not vote., 50, 50); Evaluating a single expression.
Inequalities and their Graphs
Selection Statements Make a decision based on conditions Allows the computer to be intelligent.
WHERE Clause Chapter 2. Objectives Limit rows by using a WHERE clause Use the LIKE operator Effect of NULL values Use compound conditions Use the BETWEEN.
If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
Project 6: Working with If Statements Essentials for Design JavaScript Level One Michael Brooks.
1 Pertemuan 14 PHP: Conditions-loops-functions-Array Last Updated: 23 rd May 2011 By M. Arief
What IF?.
The conditional statement General form: if ( ) { consequent-action-list } Actual Example: if (document.getElemendById(‘name’).value= ='') { alert(‘Name.
Administrative MUST GO TO CORRECT LAB SECTION! Homework due 11:59pm on Tuesday. 25 points off if late (up to 24 hours) Cannot submit after 11:59pm on Wednesday.
3-6 Compound Inequalities
2.5 Solving Proportions Write and use ratios, rates, and unit rates. Write and solve proportions.
- Meeting 5 – Making Decision By: Felix Valentin, MBA.
IDK0040 Võrgurakendused I harjutus 07: PHP: Operators, Switch, Forms Deniss Kumlander.
Write and Graph Inequalities Honors Math – Grade 8.
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.
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.
Logic Disjunction A disjunction is a compound statement formed by combining two simple sentences using the word “OR”. A disjunction is true when at.
Notes Over 6.3 Writing Compound Inequalities Write an inequality that represents the statement and graph the inequality. l l l l l l l
4.1 Solving Linear Inequalities
Ratios & Proportions 7-1 Geometry FRIDAY, Nov. 4.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Rates, Ratios, Proportions & Unit Rate By Colin C.
Logic Line-up. The Characters Cat Horton Grinch Fox.
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.
Solving Linear Inequalities and Compound Inequalities.
Chapter 12 Section 5 Solving Compound Inequalities.
Do-Now: 1) What times can you park if there is NO PARKING from 1pm- 3pm? 2) How can we write this using an inequality?
Thinking Mathematically Logic 3.4 Truth Tables for the Conditional and Biconditional.
EXAMPLE 1 Graph simple inequalities a. Graph x < 2.
 A comparison of two quantities  Often expressed as a fraction.
Solving an Absolute-Value Inequality Recall that  x  is the distance between x and 0. If  x  8, then any number between  8 and 8 is a solution of.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Types, Truth, and Expressions Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Random Functions Selection Structure Comparison Operators Logical Operator
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
Objectives Evaluate and multiply by powers of 10.
Objective #5: Solve Compound Inequalities
Fractions Greater Than, Less Than, or Equal to
3.5 Databases Relationships.
Sequence, Selection, Iteration The IF Statement
Comparison Operators Relational Operators.
Solving Absolute-Value Inequalities
Scientific Notation.
Absolute Value Inequalities
Relational Operators Operator Meaning < Less than > Greater than
Counting & Comparing Money 2 $ $ $ $.
Counting & Comparing Money $ $ $ $.
What is the difference between and and or?
Compound Inequalities
Compound Inequalities
Logical Operations In Matlab.
5-4 Compound Inequalities
Compare and Order Numbers
COMPOUND INEQUALITIES
Compound Inequalities and their Graphs
Statements of Symbolic Logic
Basic Concept of Inequalities
Relational Operators.
Notes Over 1.7 Solving Inequalities
Section 3.3 Truth Tables for the Conditional and Biconditional
Every number has its place!
Notes Over 1.7 Solving Inequalities
Operator and Expression
x ≤ 4 x = 4 x = 4 Describe the unshaded region.
A3 2.1d To Solve Compound Inequalities
Inequalities x > a Means x is greater than a
Types, Truth, and Expressions
Presentation transcript:

The conditional statement General form: if ( <condition> ) { consequent-action-list } Actual Example: if (applicationForm.name.value= ='') { alert("Name is empty") }

Conditions Many forms are possible. Equality is one type General form of equality condition: <expression> = = <value> Actual Example: applicationForm.name.value= ='’ Note that, in conditions, equality is written as two = characters, that is as = =

More on conditions Besides = = (for equality) we can use these other types of comparison operators in conditions: != not equal < less than > greater than <= less than or equal to >= greater than or equal to

More on conditions We can also build compound conditions using the following logical operators: && logical and || logical or ! logical not Examples: applnForm.name.value = = ‘Fred’ || applnForm.name.value==‘Tom’ applnForm.age.value >= 16 && applnForm.age.value <= 20

Alert actions General form of alert action: alert(<expression>) Actual Examples: alert(“Name is empty”) alert(applicationForm.name.value)

Complete docmn’t spec (Part I) <HTML> <HEAD> <TITLE> Membership Application Form </TITLE> <STYLE> FORM {BACKGROUND-COLOR : red; PADDING : 0.2in} FIELDSET {PADDING : 0.2in} BUTTON {MARGIN : 0.1in} </STYLE> <SCRIPT> function checkApplication() {if (applicationForm.name.value=='') { alert("Name is empty") } ; if (applicationForm.email.value=='') { alert("Email address is empty") } } </SCRIPT> </HEAD>

Complete docmn’t spec (Part II) <BODY> <P> If you want to join our club, complete the form below and we will get back to you. </P> <FORM NAME=applicationForm METHOD="post" ACTION="/cgi-bin/appln.cgi"> <H1> Membership Application Form</H1> <FIELDSET> <LEGEND>Contact Information</LEGEND> What is your name? <INPUT TYPE=text NAME=name> Please enter your email address: <INPUT TYPE=text NAME=email> </FIELDSET>

Complete docmn’t spec (Part III) <FIELDSET> <LEGEND>Form Submission</LEGEND> <P><BUTTON TYPE=button onClick='checkApplication()'> Check application</BUTTON> <BUTTON TYPE=submit>Submit application</BUTTON> </P> </FIELDSET> </FORM> </BODY> </HTML>

The SIZE attribute In the examples so far, INPUT elements of TYPE=text were given, on the form, a user-input box of a default size You can, however, specify the exact size you want, by using the attribute SIZE Examples: <INPUT TYPE=text NAME=name SIZE=10> <INPUT TYPE=text NAME=email SIZE=40> You can see the effect of these size specifications on the next slide WARNING: Microsoft Internet Explorer 5.0 actually makes user-input boxes one character longer than your specified size! Navigator 4.08 does not -- but, then again, it does not yet handle fieldsets either!

Length of user-input versus size of user-input box The user’s input is not restricted to the size of the user-input box On the next four slides, you can see, from the server-side responses, that the user input names which were much longer than the user-input box

User’s input exceeds default size of user-input box

Here we can see how long the user’s name really was

User’s input can exceed a box of specified SIZE too:

Again, we see the full-name:

We can, however, impose an upper-limit on the user’s input: We can use the MAXLENGTH attribute Example <INPUT TYPE=text NAME=localPhoneNumber SIZE=6 MAXLENGTH=6> This is used on the next slide: when the user tries to input more than 6 characters in this box the browser refuses to accept them (even though the form shows the box as longer than 6 characters!)

More types of INPUT elements We have already seen INPUT elements of TYPE=text But there are other TYPEs of INPUT element. The full list of types is: text password checkbox radio submit reset file hidden image button INPUT elements of TYPE=password are similar to elements of TYPE=text -- the only difference is that the user’s input is echoed as so-called “masking” characters Example: <INPUT TYPE=password NAME=desiredPassword> This is used on next slide

Of course, the server does not send the password back:

INPUTs of TYPE=checkbox An INPUT element of TYPE=checkbox produces a little box into which the user can place a  mark to indicate a desire to select the value that is associated with the element This type of element must have a VALUE attribute to specify the associated value Example <INPUT TYPE=checkbox NAME=colour VALUE=navyBlue> If the user places a  in the box produced by this element the server-side program would be told that the user selected navyBlue as a colour Three check-boxes are used on the next slide

Using the checkboxes By clicking on one or more of these checkboxes, the user can select one or more T-shirts that he wants to order

Form Specification: <FORM METHOD="post" ACTION="/cgi-bin/tshirts.cgi"> <FIELDSET> <LEGEND>Order</LEGEND> <P> What is your name? <INPUT TYPE=text NAME=name SIZE=10> </P> <P> Please select which style(s) of T-shirt you want: </P> <UL> <LI> <INPUT TYPE=checkbox NAME=products VALUE=Batman> Batman's cloak </LI> <LI> <INPUT TYPE=checkbox NAME=products VALUE=Superman> Superman’s cloak</LI> <LI> <INPUT TYPE=checkbox NAME=products VALUE="Dr. Who"> Dr. Who's coat</LI> </UL> </FIELDSET> <LEGEND>Form Submission</LEGEND> <P> <BUTTON TYPE=submit>Submit order</BUTTON> </P> </FORM>

Oh, by the way: On the screen below, we eliminate list “bullets” by the following line in a stylesheet LI {LIST-STYLE-TYPE : none}

Using text with checkboxes You must use text with checkboxes otherwise, the user will not know what he is selecting this is because the VALUE associated with the checkbox is not printed by a browser Example: <INPUT TYPE=checkbox NAME=products VALUE=Batman> Batman's cloak The user sees Batman's cloak in the browser beside the checkbox

Multiple checkboxes with same NAME Notice that we can have multiple checkboxes with the same name: <UL> <LI> <INPUT TYPE=checkbox NAME=products VALUE=Batman> Batman's cloak </LI> <LI> <INPUT TYPE=checkbox NAME=products VALUE=Superman> Superman’s cloak</LI> <LI> <INPUT TYPE=checkbox NAME=products VALUE="Dr. Who"> Dr. Who's coat</LI> </UL> If the user selects more than one checkbox with the same name, several equations involving this name are sent to the server-side program, e.g.: products=Batman products=Superman

Default selection of checkboxes The web page on the next slide is trying to encourage the user to buy the Superman T-shirt It does so by “pre-selecting” the checkbox for this T-shirt and by having some associated “pushy” text

More on default selection A checkbox is preselected by using the word CHECKED in the INPUT element: <UL> <LI> <INPUT TYPE=checkbox NAME=products VALUE=Batman> Batman's cloak </LI> <LI> <INPUT TYPE=checkbox NAME=products VALUE=Superman CHECKED> Superman's cloak (our best-selling item)</LI> <LI> <INPUT TYPE=checkbox NAME=products VALUE="Dr. Who"> Dr. Who's coat</LI> </UL> The user can, of course, remove the  from a checkbox by clicking on the box

INPUT elements of TYPE=radio The word radio derives from the concept of “radio buttons” -- the station selection buttons on car-radios Properties of radio buttons: they represent alternatives only one alternative can be selected selecting one alternative has the side-effect of automatically de-selecting any previous selection INPUT elements of TYPE=radio have the same properties

More on INPUT elements of TYPE=radio The following slide shows a radio button version of the previous order form Now the user can buy only one T-shirt

Suppose the user has selected the Batman T-shirt

If he now clicks the Dr. Who button, Batman is deselected

Implementation of the above: <UL> <LI> <INPUT TYPE=radio NAME=products VALUE=Batman> Batman's cloak </LI> <LI> <INPUT TYPE=radio NAME=products VALUE=Superman> Superman's cloak</LI> <LI> <INPUT TYPE=radio NAME=products VALUE="Dr. Who"> Dr. Who's coat</LI> </UL>

Preselection of radio buttons Just as checkboxes can be preselected, one radio button in a group which all have the same NAME can be preselected HOWEVER, more than one checkbox can be preselected but ONLY ONE radio button can be preselected

Example <UL> <LI> <INPUT TYPE=radio NAME=products VALUE=Batman> Batman's cloak </LI> <LI> <INPUT TYPE=radio NAME=products VALUE=Superman CHECKED> Superman's cloak (our best-selling item)</LI> <LI> <INPUT TYPE=radio NAME=products VALUE="Dr. Who"> Dr. Who's coat</LI> </UL>

Other types of INPUT element There are some types of INPUT element that we have not considered: TYPE=hidden TYPE=file TYPE=image They have their uses but are too specialized to be considered here You should study their uses yourself

Cs 3314 got here on 5 nov 2005 still have to discuss hidden elements

Other user-input elements So far we have considered two classes of user-input elements: the BUTTON element the INPUT element There are two other kinds: the SELECT element the TEXTAREA element