13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

66<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>else{TextBox2.Text = n2 + " is greater";}}}When you test the script, enter two different integers; which one is greater shows in thetext box, as shown in Figure 3-1.To handle more than a single condition, you can use a series of if or else ifstatements using the following format:if(conditionA){//do A}else if (conditionB){//do B}When faced with more than a single condition to resolve, the else if statementwill do the trick. It can get a little messy when you have several alternative out<strong>com</strong>es toevaluate.SwitchWhen you have several different out<strong>com</strong>es, else if be<strong>com</strong>es a bit cumbersome, but itworks fine. A better alternative than else if is the switch statement, which can handleany number of conditional values. The switch statement takes the value of a singlevariable and then examines several different cases to decide which to use. Most switchstatements also contain a break statement at the end so that when the matching case isAsk the ExpertQ: In the last example, nothing happens if the numbers are equal. How do you deal withvalues that are equal?A: If you only use a single condition, use the greater-than or equal-to operator (>=) so that theequal condition can be included.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!