Академический Документы
Профессиональный Документы
Культура Документы
Objectives
Make choices using conditional statements Manage flow control using branching statements Repeat blocks of code using looping statements Break out of loops when necessary
Agenda
Branching in Code Repeating Code Blocks Unconditional Branching
Branching in Code
Any programming language must provide means of branching in code Procedure may need to execute one statement if a condition is true
Optionally, execute a second statement if the condition is false
.NET provides several different techniques for making decisions as code executes
Conditional branching covered here Unconditional branching covered as necessary
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Conditional Branching
Code can "make decisions" as it's executing
If statements Single-Line If statements If/Else statements Nested If statements Testing for multiple conditions Comparing a condition to a single value
If Statements
Allows you to execute a block of code if a condition is true
Skips the code if the condition isn't true
Case statements can include comparisons other than equality (the default comparison) Case statements can include comma-delimited lists of values Visual Basic evaluates Case statements from top to bottom
o
If no other cases match, Visual Basic executes code in the else block
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Agenda
Branching in Code Repeating Code Blocks Unconditional Branching
Unbounded Looping
Several different options available for repeating a block of code while a condition remains true
While loop Do loop
Allows you to check the condition at the top or bottom of the loop
Allows you to loop while or until the condition remains true or changes
Placing check for the condition at the bottom of the loop guarantees that the code runs at least once
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
Like most languages, Visual Basic and C# provide a way to loop through a range of integer values
Can increment or decrement the looping variable By 1 or some other value
Learn More @ http://www.learnnowonline.com
Copyright by Application Developers Training Company
As you remove items, they renumber Removing from front to back would break the collection
Agenda
Branching in Code Repeating Code Blocks Unconditional Branching
If you have nested loops, you can exit from any of the loops, at any level
Loops must be of different types for this to work
Continue Statement
What if you want to jump back to the top of a loop without executing the rest of the statements in the loop?
Continue statement solves this problem
Learn More!
This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn more about .NET on SlideShare:
Getting Started with .NET .NET Variables and Data Types Using the .NET Framework