|
Hot-Link Menu in Right-Side Column |
Last Updated 6-30-2010 |
||||||||||||||||||||||||||||||||||||||||||
|
7.12 Nested LoopsA loop can be coded within another loop thus forming nested loops. There can be many levels of nesting. Needless to say, there can be a selection structure coded inside a loop, a loop coded in a selection structure, and so on. Such nesting is possible as long as the inner structure is completely enclosed in the outer structure. Nested loops do have application in programming. For example, nested loops are needed to display a table of values, to process the elements of a two-dimensional array, or to sort array elements using the Bubble Sort algorithm. Let us look at an example:
Visual Basic VB.NET - Example 10Assignment: Design a VB.NET project to display a multiplication table for numbers 1 to 10 on the screen. To do this, you need to display 10 rows, and in each row you have to display 10 values, which is the product of the row # by the column #. The outer loop will go through the rows, and the inner loop will go through the columns. Notice that for each cycle of the outer loop, i.e. for each row, the inner loop has to through all the cycles, i.e., all the columns. Let us design a simple GUI for this project with one Button and one Label, and write the code in the click event procedure of the Button.
Solution to 7.10Modify the properties of the Label, Button and Form as indicated in the diagrams below. Double-Click on the Display button to open the code box, and enter the code supplied below.
|
Home Visual Basic Introduction to VB.NET.NET Framework VS2008 IDE How VB is Compiled Start Visual Studio Windows Form App Save Your Work VB OOP ProgrammingVisual Basic Code Exit Code Button Event Code Coding RecommendationsIf/Then/Else Error List Window Comment Syntax Help Window Language Essentianl Built-In Data Types Declare Variables Declare ConstantsCode Arithmetic Expressions Assignment Statements Operator Precedence Type Casting Math Class String DeclarationConversion Functions Conversion Methods Formatting Functions String Formatting Variable Scope EnumerationsNullable Types Loop Constructs For Next LoopDo While Loop Do Until Loop Do...Loop-WhileDo...Loop-Until Exit Do | Exit For Do...LoopNested Loops Arrays Array DeclarationRnd( ) Function Listbox ControlKeyPressEventArgs Parallel Arrays Key Event ArgsDynamic Arrays Redimension ArraySet Breakpoint Start Debugger ReDim Preserve MultiDimensional Arrays DataGridView ControlLength and Sort Methods Structures Pad RightSplit Method IsNumeric Function Multiform Projects Add Form To Project Form Object Methods Form Show Method ShowDialog Method Form Close Method Form Accept Button Multiform Project Example ASP.NET Web Programming Create Data SourceConfigure Access Data Source Add Product Class Extract Local Database Data Order PageLoad VB CodeAdd New Web Page Set Start Page Display Cart Aspx CodeDisplay Cart Design View Sorted List Definition VB.NET Session State Create CartItem Class GetCartContents FunctionAdd To Cart Event Handler Remove Cart Item EventClear Cart Event Handler |