Application of .NET Technology Unit 08 Advanced Programming Constructs Notes Set 01

Computer Science Study Guide: Application of .NET Technology Unit 08 Advanced Programming Constructs Notes Set 01

Access comprehensive study materials and useful resources for .NET Technology using the Application of .NET Technology Unit 08 Advanced Programming Constructs Notes Set 01. Designed to align with the 2026-27 academic guidelines, these advanced resources help Computer Science students reinforce core concepts beyond standard textbooks.

Download .NET Technology Study Material PDF

Access the complete useful resource PDF for Computer Science below. Regular practice with these targeted academic notes builds familiarity with complex topics and helps secure higher marks in final school evaluations.

This page walks through unit 8 of VB.Net programming: procedures and functions with parameter passing, recursion and param arrays, modules and variable declaration, and a first console program. It continues with fixed, dynamic, multi-dimensional and jagged arrays, the Array class, selection and looping constructs, and the collection classes ArrayList, Hashtable, SortedList, Stack, Queue and BitArray.

Procedures

A procedure is a group of statements that together perform a task when called.
After the procedure is executed, the control returns to the statement calling the procedure.
VB.Net has two types of procedures:
1. Functions
2. Sub procedures or Subs
Functions return a value, whereas Subs do not return a value.

Sub-procedures

The Sub statement is used to declare the name, parameter and the body of a sub procedure. The syntax for the Sub statement is:

[Modifiers] Sub SubName [(ParameterList)]
   [Statements]
End Sub

Where,
Modifiers: specify the access level of the procedure; possible values are: Public, Private, Protected, Friend, Protected Friend and information regarding overloading, overriding, sharing, and shadowing.
SubName: indicates the name of the Sub.
ParameterList: specifies the list of the parameters.

Example for sub-procedure

The following example demonstrates a Sub procedure CalculatePay that takes two parameters hours and wages and displays the total pay of an employee:

Module mysub
   Sub CalculatePay(ByVal hours As Double, ByVal wage As Decimal)
      'local variable declaration
      Dim pay As Double
      pay = hours * wage
      Console.WriteLine("Total Pay: {0:C}", pay)
   End Sub
   Sub Main()
      'calling the CalculatePay Sub Procedure
      CalculatePay(25, 10)
      CalculatePay(40, 20)
      CalculatePay(30, 27.5)
      Console.ReadLine()
   End Sub
End Module

When the above code is compiled and executed, it produces the following result:

Total Pay: $250.00
Total Pay: $800.00
Total Pay: $825.00

The example program shows how to calculate pay by taking the parameters such as hours and wages using sub procedure.
Here the procedure CalculatePay is the sub procedure, where local variables are declared.
At the end of the sub procedure the main function is stated, which is used to call the procedure with different parameters.

Passing Parameters by Value

This is the default mechanism for passing parameters to a method.
In this mechanism, when a method is called, a new storage location is created for each value parameter.
The values of the actual parameters are copied into them.
So, the changes made to the parameter inside the method have no effect on the argument.
In VB.Net, you declare the value parameters using the ByVal keyword.
The following example demonstrates the concept:

Program

Module paramByval
   Sub swap(ByVal x As Integer, ByVal y As Integer)
      Dim temp As Integer
      temp = x ' save the value of x
      x = y    ' put y into x
      y = temp 'put temp into y
   End Sub
   Sub Main()
      ' local variable definition
      Dim a As Integer = 100
      Dim b As Integer = 200
      Console.WriteLine("Before swap, value of a : {0}", a)
      Console.WriteLine("Before swap, value of b : {0}", b)
      ' calling a function to swap the values '
      swap(a, b)
      Console.WriteLine("After swap, value of a : {0}", a)
      Console.WriteLine("After swap, value of b : {0}", b)
      Console.ReadLine()
   End Sub
End Module

Output

Before swap, value of a :100
Before swap, value of b :200
After swap, value of a :100
After swap, value of b :200

Passing parameters by values is the default method in any language.
Here the parameter is passed directly to the function.
It shows that there is no change in the values though they had been changed inside the function.

Passing Parameters by Reference

A reference parameter is a reference to a memory location of a variable.
When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters.
The reference parameters represent the same memory location as the actual parameters that are supplied to the method.
In VB.Net, you declare the reference parameters using the ByRef keyword.
The following example demonstrates this:

Program

Module paramByref
   Sub swap(ByRef x As Integer, ByRef y As Integer)
      Dim temp As Integer
      temp = x ' save the value of x
      x = y    ' put y into x
      y = temp 'put temp into y
   End Sub
   Sub Main()
      ' local variable definition
      Dim a As Integer = 100
      Dim b As Integer = 200
      Console.WriteLine("Before swap, value of a : {0}", a)
      Console.WriteLine("Before swap, value of b : {0}", b)
      ' calling a function to swap the values '
      swap(a, b)
      Console.WriteLine("After swap, value of a : {0}", a)
      Console.WriteLine("After swap, value of b : {0}", b)
      Console.ReadLine()
   End Sub
End Module

Output

Before swap, value of a : 100
Before swap, value of b : 200
After swap, value of a : 200
After swap, value of b : 100

The example program shows how the procedure is called by passing parameters by reference.
In VB.Net, you declare the reference parameters using the ByRef keyword.
The parameter passing is located by the same memory location.
The pointer concept is used in this method.

Function

Function is a group of statements.
It should be executed once it is called.
The function call is referred by a value or by a reference.
The Function statement is used to declare the name, parameter and the body of a function.
The syntax for the Function statement is:

[Modifiers] Function FunctionName [(ParameterList)] As ReturnType
   [Statements]
End Function

Where,
Modifiers: specify the access level of the function; possible values are: Public, Private, Protected, Friend, Protected Friend and information regarding overloading, overriding, sharing, and shadowing.
FunctionName: indicates the name of the function.
ParameterList: specifies the list of the parameters.
ReturnType: specifies the data type of the variable the function returns.

Example for function

Here is an example for function.
Following code snippet shows a function FindMax that takes two integer values and returns the larger of the two.
The function name is FindMax, and it is called by value.
The program is an example of finding the biggest number among the given numbers.

Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
   Dim result As Integer
   If (num1 > num2) Then
      result = num1
   Else
      result = num2
   End If
   FindMax = result
End Function

Function Returning a Value

In VB.Net, a function can return a value to the calling code in two ways:
1. By using the return statement.
2. By assigning the value to the function name.
The following example demonstrates using the FindMax function:

Module myfunctions
   Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
      Dim result As Integer
      If (num1 > num2) Then
         result = num1
      Else
         result = num2
      End If
      FindMax = result
   End Function
   Sub Main()
      Dim a As Integer = 100
      Dim b As Integer = 200
      Dim res As Integer
      res = FindMax(a, b)
      Console.WriteLine("Max value is : {0}", res)
      Console.ReadLine()
   End Sub
End Module

The example shows how to return a value from a function.
The value is returned to the calling code when the function is executed.
When the above code is compiled and executed, it produces the following result:

Max value is : 200

Recursive Function

A function can call itself.
This is known as recursion.
Following is an example that calculates factorial for a given number using a recursive function:

Module myfunctions
   Function factorial(ByVal num As Integer) As Integer
      ' local variable declaration
      Dim result As Integer
      If (num = 1) Then
         Return 1
      Else
         result = factorial(num - 1) * num
         Return result
      End If
   End Function
   Sub Main()
      'calling the factorial method
      Console.WriteLine("Factorial of 6 is : {0}", factorial(6))
      Console.WriteLine("Factorial of 7 is : {0}", factorial(7))
      Console.WriteLine("Factorial of 8 is : {0}", factorial(8))
      Console.ReadLine()
   End Sub
End Module

If a function calls itself, that function is called a recursive function.
Here the example shows the recursive function by calculating the factorial for the given number.
The result for the program is:

Factorial of 6 is: 720
Factorial of 7 is: 5040
Factorial of 8 is: 40320

Param Arrays

At times, while declaring a function or sub procedure, you are not sure of the number of arguments passed as a parameter.
VB.Net param arrays come into help at these times.
The following example demonstrates this:

Module myparamfunc
   Function AddElements(ParamArray arr As Integer()) As Integer
      Dim sum As Integer = 0
      Dim i As Integer = 0
      For Each i In arr
         sum += i
      Next i
      Return sum
   End Function
   Sub Main()
      Dim sum As Integer
      sum = AddElements(512, 720, 250, 567, 889)
      Console.WriteLine("The sum is: {0}", sum)
      Console.ReadLine()
   End Sub
End Module

Param Array is also called a dynamic array.
When we do not know the number of arguments passed as a parameter when declaring an array we can use a param array.
The example program shows how to use a param array.
The result of this program is:

The sum is: 2938

Passing Arrays as Function Arguments

You can pass an array as a function argument in VB.Net.
The following example demonstrates this:

Module arrayParameter
   Function getAverage(ByVal arr As Integer(), ByVal size As Integer) As Double
      'local variables
      Dim i As Integer
      Dim avg As Double
      Dim sum As Integer = 0
      For i = 0 To size - 1
         sum += arr(i)
      Next i
      avg = sum / size
      Return avg
   End Function
   Sub Main()
      ' an int array with 5 elements '
      Dim balance As Integer() = {1000, 2, 3, 17, 50}
      Dim avg As Double
      'pass pointer to the array as an argument
      avg = getAverage(balance, 5)
      ' output the returned value '
      Console.WriteLine("Average value is: {0} ", avg)
      Console.ReadLine()
   End Sub
End Module

The special feature in VB is passing an array as a function argument for a function or procedure.
The example shows the syntax for passing an array as an argument.
The result for this program is:

Average value is: 214.4

Modules

A VB.Net program is made up of variables and programming statements enclosed in a module.
This is a big step for someone to understand.
The simplest way to understand this is just to realize that variables and programming statements need to be grouped together by something.
This something is called a module.
A VB program is a set of two parts. They are:
1. Variables
2. Programming statements
A variable is nothing but a name given to a storage area that our programs can manipulate.
Each variable in VB.Net has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

Declaring Variables

Before you can use a variable in a program it has to be declared.
To declare a variable you use the Dim keyword and specify a data type from the preceding data type table.
In the example Dim x As Integer, x is declared as a variable of Integer data type. Dim means declare variable, As means specify a data type.

Dim number As Integer
Dim quantity As Integer = 100
Dim message As String = "Hello!"

The Dim statement is used for variable declaration and storage allocation for one or more variables.
The Dim statement is used at module, class, structure, procedure or block level.

Syntax for variable declaration in VB.Net is

[ <attributelist> ] [ accessmodifier ] [[ Shared ] [ Shadows ] | [ Static ]]
[ ReadOnly ] Dim [ WithEvents ] variablelist

Explanation:
attributelist is a list of attributes that apply to the variable. Optional.
accessmodifier defines the access levels of the variables, it has values as - Public, Protected, Friend, Protected Friend and Private. Optional.
Shared declares a shared variable, which is not associated with any specific instance of a class or structure, rather available to all the instances of the class or structure. Optional.
Shadows indicate that the variable re-declares and hides an identically named element, or set of overloaded elements, in a base class. Optional.
Static indicates that the variable will retain its value, even after termination of the procedure in which it is declared. Optional.
ReadOnly means the variable can be read, but not written. Optional.
WithEvents specifies that the variable is used to respond to events raised by the instance assigned to the variable.
variablelist provides the list of variables declared.

Each variable in the variable list has the following syntax and parts

variablename[ ( [ boundslist ] ) ] [ As [ New ] datatype ] [ = initializer ]

variablename: is the name of the variable.
boundslist: optional. It provides list of bounds of each dimension of an array variable.
New: optional. It creates a new instance of the class when the Dim statement runs.
datatype: Required if Option Strict is On. It specifies the data type of the variable.
initializer: Optional if New is not specified. Expression that is evaluated and assigned to the variable when it is created.

Some valid variable declarations along with their definition are shown here

The examples show valid declarations in VB.Net.

Dim StudentID As Integer
Dim StudentName As String
Dim Salary As Double
Dim count1, count2 As Integer
Dim status As Boolean
Dim exitButton As New System.Windows.Forms.Button
Dim lastTime, nextTime As Date

Variable Initialization in VB.Net

Variables are initialized (assigned a value) with an equal sign followed by a constant expression.
The general form of initialization is:

variable_name = value

For example,

Dim pi As Double
pi = 3.14159

To initialize a variable we first write the variable name, then the equal sign, and then the constant.
The syntax shows how to initialize the variables in VB.Net.
This is the common method for all high level languages.
You can initialize a variable at the time of declaration as follows:

Dim StudentID As Integer = 100
Dim StudentName As String = "Bill Smith"

Example for Variable declaration and Variable Initialization

The program shows how to declare the variables and how to initialize the variables.

Module variablesNdataypes
   Sub Main()
      Dim a As Short
      Dim b As Integer
      Dim c As Double
      a = 10
      b = 20
      c = a + b
      Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c)
      Console.ReadLine()
   End Sub
End Module

When the above code is compiled and executed, it produces the following result:

a = 10, b = 20, c = 30

Accepting Values from User

Dim message As String
message = Console.ReadLine

The Console class in the System namespace provides a function ReadLine for accepting input from the user and store it into a variable.
For example,
It is hard to give the input by the program, as such programs are static programs.
No different output would be produced.
For this reason the syntax has been created to give the input at running time.
The example shows how to declare a variable for run time initialization.

Module variablesNdataypes
   Sub Main()
      Dim message As String
      Console.Write("Enter message: ")
      message = Console.ReadLine
      Console.WriteLine()
      Console.WriteLine("Your Message: {0}", message)
      Console.ReadLine()
   End Sub
End Module

When the above code is compiled and executed, it produces the following result.

Enter message: Hello World
Your Message: Hello World

Lvalues and Rvalues

There are two kinds of expressions:
Lvalue: An expression that is an lvalue may appear as either the left-hand or right-hand side of an assignment.
Rvalue: An expression that is an rvalue may appear on the right- but not left-hand side of an assignment.
Example:

Dim g As Integer = 20

VB .Net Sample Program

We are now ready to write our first VB.Net program.
In this sample program we will initialize some variables and print their values to the screen.
Programming languages use programming statements to do things.
A statement includes command words called keywords and data values.
Our statement will be a statement that allows you to print out messages on the computer screen.
Messages are String constants enclosed by " double quotes " like "hello".
This is a Console program, meaning the output is sent to the screen, and the user types in the input responses.
A Console program is a little different than a GUI program.
In our program we first declare a name and age variable.

Dim name As String
Dim age As Integer

We then initialize name to "Tom" and age to 20.

name = "Tom"
age = 20

Now we want to print the name and age to the screen.
We use the Console.Write and Console.WriteLine statements to do this.
Here we print the "Hi, my name is Tom" message on the computer screen.

Example program

You will notice it is enclosed in a Module and a Sub called Main.
The Sub encloses the programming statements. The Module encloses the Sub Main.
A module can have many Subs.
The Main Sub is the first sub to start executing in a module contained in a program.

Module Module1
Sub Main()
Dim name As String
Dim age As Integer
name = "Tom"
age = 20
Console.Write("Hi, my name is ")
Console.WriteLine(name)
Console.Write("I am now ")
Console.Write(age)
Console.WriteLine(" years old.")
Console.Read() ' pause
End Sub
End Module

Step-by-step instructions to run the program

Before you can write and run this program you first need to create a new Project.
Make sure you have Visual Basic .Net installed on your computer.
We are using Visual Basic .Net version 2005.

Step 1: Open up Visual Basic .Net, from the File menu select New then Project.
Step 2: Right-click on Form1 in the Project Explorer window and select Remove Form1 from the pop up window. (this is an optional step)
Step 3: You should make a directory for your programs using Windows Explorer and then use the browse button to select that directory. Select Console Application and then type in the name of the program.
Step 4: Now type in the program.
Step 5: To run the program select Start from the Debug menu.

Array

An array is a collection of data stored in continuous order.
It is a linear data structure to access the data.
An array stores a fixed-size sequential collection of elements of the same type.
An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
All arrays consist of contiguous memory locations.
The lowest address corresponds to the first element and the highest address to the last element.

Creating Arrays in VB.Net

To declare an array in VB.Net, you use the Dim statement. For example,

Dim intData(30)
Dim strData(20) As String
Dim twoDarray(10, 20) As Integer
Dim ranges(10, 100)

You can also initialize the array elements while declaring the array. For example,

Dim intData() As Integer = {12, 16, 20, 24, 28, 32}
Dim names() As String = {"Karthik", "Sandhya", _
"Shivangi", "Ashwitha", "Somnath"}
Dim miscData() As Object = {"Hello World", 12d, 16ui, "A"c}

The example shows how to create, access and operate the array.
Dim is used to declare the array.
The value may be declared at the access time or at the run time.
The elements in an array can be stored and accessed by using the index of the array.
The following program demonstrates this:

Module arrayApl
   Sub Main()
      Dim n(10) As Integer ' n is an array of 11 integers '
      Dim i, j As Integer

      For i = 0 To 10
         n(i) = i + 100 ' set element at location i to i + 100
      Next i
      For j = 0 To 10
         Console.WriteLine("Element({0}) = {1}", j, n(j))
      Next j
      Console.ReadKey()
   End Sub
End Module

This is the sample code for declaring and accessing the array.
The Console is used to write the output of the program in the output box.
It is a program to print from 100 to 110 using a for loop.
When the above code is compiled and executed, it produces the following result:

Element(0) = 100
Element(1) = 101
Element(2) = 102
Element(3) = 103
Element(4) = 104
Element(5) = 105
Element(6) = 106
Element(7) = 107
Element(8) = 108
Element(9) = 109
Element(10) = 110

Dynamic Arrays

Dynamic arrays are arrays that can be dimensioned and re-dimensioned as per the need of the program.
You can declare a dynamic array using the ReDim statement.
Syntax for ReDim statement:

ReDim [Preserve] arrayname(subscripts)

Where,
The Preserve keyword helps to preserve the data in an existing array, when you resize it.
arrayname is the name of the array to re-dimension.
subscripts specifies the new dimension.
Sample program:

Module arrayApl
   Sub Main()
      Dim marks() As Integer
      ReDim marks(2)
      marks(0) = 85
      marks(1) = 75
      marks(2) = 90
      ReDim Preserve marks(10)
      marks(3) = 80
      marks(4) = 76
      marks(5) = 92
      marks(6) = 99
      marks(7) = 79
      marks(8) = 75
      For i = 0 To 10
         Console.WriteLine(i & vbTab & marks(i))
      Next i
      Console.ReadKey()
   End Sub
End Module

In a dynamic array the length should be declared dynamically.
It is declared by using the ReDim statement.
There is no special reason for the name ReDim; it is the syntax used for dynamic array declaration.
It produces the following result:

0	85
1	75
2	90
3	80
4	76
5	92
6	99
7	79
8	75
9	0
10	0

Multi-Dimensional Arrays

VB.Net allows multidimensional arrays.
Multidimensional arrays are also called rectangular arrays.
You can declare a 2-dimensional array of strings as:

Dim twoDStringArray(10, 20) As String

A 3-dimensional array of Integer variables:

Dim threeDIntArray(10, 10, 10) As Integer

The following program demonstrates creating and using a 2-dimensional array:

Module arrayApl
   Sub Main()
      Dim a(,) As Integer = {{0, 0}, {1, 2}, {2, 4}, {3, 6}, {4, 8}}
      Dim i, j As Integer
      For i = 0 To 4
         For j = 0 To 1
            Console.WriteLine("a[{0},{1}] = {2}", i, j, a(i, j))
         Next j
      Next i
      Console.ReadKey()
   End Sub
End Module

Jagged Array

Declaring an array using a defined array is called a jagged array.
A jagged array is an array of arrays.
The following code shows declaring a jagged array named scores of Integers.

Dim scores As Integer()() = New Integer(5)() {}

The following example illustrates using a jagged array:

Module arrayApl
   Sub Main()
      'a jagged array of 5 array of integers
      Dim a As Integer()() = New Integer(4)() {}
      a(0) = New Integer() {0, 0}
      a(1) = New Integer() {1, 2}
      a(2) = New Integer() {2, 4}
      a(3) = New Integer() {3, 6}
      a(4) = New Integer() {4, 8}
      Dim i, j As Integer
      ' output each array element's value
      For i = 0 To 4
         For j = 0 To 1
            Console.WriteLine("a[{0},{1}] = {2}", i, j, a(i)(j))
         Next j
      Next i
      Console.ReadKey()
   End Sub
End Module

The Array Class

The Array class is the base class for all the arrays in VB.Net.
It is defined in the System namespace.
The Array class provides various properties and methods to work with arrays.

Properties of the Array Class

NameDescription
IsFixedSizeGets a value indicating whether the Array has a fixed size.
IsReadOnlyGets a value indicating whether the Array is read-only.
LengthGets a 32-bit integer that represents the total number of elements in all the dimensions of the Array.
LongLengthGets a 64-bit integer that represents the total number of elements in all the dimensions of the Array.
RankGets the rank (number of dimensions) of the Array.

Methods of the Array Class

NameDescription
Public Shared Sub Clear ( array As Array, index As Integer, length As Integer )Sets a range of elements in the Array to zero, to false, or to null, depending on the element type.
Public Shared Sub Copy ( sourceArray As Array, destinationArray As Array, length As Integer )Copies a range of elements from an Array starting at the first element and pastes them into another Array starting at the first element. The length is specified as a 32-bit integer.
Public Sub CopyTo ( array As Array, index As Integer )Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index. The index is specified as a 32-bit integer.
Public Function GetLength ( dimension As Integer ) As IntegerGets a 32-bit integer that represents the number of elements in the specified dimension of the Array.
Public Function GetLongLength ( dimension As Integer ) As LongGets a 64-bit integer that represents the number of elements in the specified dimension of the Array.
Public Function GetLowerBound ( dimension As Integer ) As IntegerGets the lower bound of the specified dimension in the Array.
Public Function GetType As TypeGets the Type of the current instance (Inherited from Object).
Public Function GetUpperBound ( dimension As Integer ) As IntegerGets the upper bound of the specified dimension in the Array.
Public Function GetValue ( index As Integer ) As ObjectGets the value at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.
Public Shared Function IndexOf ( array As Array, value As Object ) As IntegerSearches for the specified object and returns the index of the first occurrence within the entire one-dimensional Array.
Public Shared Sub Reverse ( array As Array )Reverses the sequence of the elements in the entire one-dimensional Array.
Public Sub SetValue ( value As Object, index As Integer )Sets a value to the element at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.
Public Shared Sub Sort ( array As Array )Sorts the elements in an entire one-dimensional Array using the IComparable implementation of each element of the Array.
Public Overridable Function ToString As StringReturns a string that represents the current object (Inherited from Object).

Example

The following program demonstrates use of some of the methods of the Array class:

Module arrayApl
   Sub Main()
      Dim list As Integer() = {34, 72, 13, 44, 25, 30, 10}
      Dim temp As Integer() = list
      Dim i As Integer
      Console.Write("Original Array: ")
      For Each i In list
         Console.Write("{0} ", i)
      Next i
      Console.WriteLine()
      ' reverse the array
      Array.Reverse(temp)
      Console.Write("Reversed Array: ")
      For Each i In temp
         Console.Write("{0} ", i)
      Next i
      Console.WriteLine()
      'sort the array
      Array.Sort(list)
      Console.Write("Sorted Array: ")
      For Each i In list
         Console.Write("{0} ", i)
      Next i
      Console.WriteLine()
      Console.ReadKey()
   End Sub
End Module

This is the sample program using the Array class methods.
Not all the methods are implemented here; the most important methods are shown.
Result of the program:

Original Array: 34 72 13 44 25 30 10
Reversed Array: 10 30 25 44 13 72 34
Sorted Array: 10 13 25 30 34 44 72

Control Flow

In a program, statements may be executed sequentially, selectively or iteratively.
Every programming language provides constructs to support sequence, selection or iteration.
So there are three types of programming constructs:
1. Sequential Constructs
2. Selection Constructs
3. Iterative Constructs

Sequential Construct

The sequential construct means the statements are being executed sequentially.
This represents the default flow of statements.
The program starts at a point and goes in sequence; this is called sequential flow.
It does not contain any jump statements.
It is the default control in high level languages.

Selection Construct

The selection construct means the execution of statement(s) depending upon the condition-test.
If a condition evaluates to true, a course-of-action (a set of statements) is followed otherwise another course-of-action is followed.
This construct is also called decision construct as it helps in decision making.
The conditions determine the controlling execution.
For example, in jump A, if this statement executes, the next step will move to the statement A.

Iterative Constructs

The iterative or repetitive constructs means repetition of a set-of-statements depending upon a condition-test.
A set-of-statements is repeated again and again till the condition or Boolean expression evaluates to the required value.
The iteration constructs are also called looping constructs.
The looping statement determines the controlling execution.
There are many iterative statements, for example For, While, increment and decrement statements.
Boolean expressions are used to decide when the loop stops.

Selection Constructs

There are two types of selection construct in VB as in other higher level languages. They are:
1. If statement
2. Select Case statement

If Statement

The If statement of VB comes in various forms given below:
1. If..Then Statement
2. If..Then..Else Statement
3. If..Then..ElseIf Statement
4. Nested If

An If..Then statement tests a particular condition; if the condition evaluates to true, a course-of-action is followed otherwise it is ignored.
If..Then..Else statement provides an alternate choice to the user i.e. if the condition is true then a set of statements are executed otherwise another set of statements are executed.
If..Then..ElseIf statement is used to test a number of mutually exclusive cases and only executes one set of statements for the case that is true first.
A nested If is an If that has another If in its If's body or in its Else's body.
The nested If can have one of three forms.

Select-Case Statement

Select-Case is a multiple branching statement and is used to execute a set of statements depending upon the value of the expression.
It is better to use the Select-Case statement in comparison to the If..Then..ElseIf statement when the number of checks is more.
The conditions determine the controlling execution.

Different forms of Select-Case

Select Case: Simplest Form [Exact match]

Select Case Expression
   Case Value
      'one or more visual basic statements
   Case Value
      'one or more visual basic statements
   Case Else :
      'one or more visual basic statements
End Select

EXAMPLE

Select Case byMonth
   Case 1, 3, 5, 7, 8, 10, 12
      number_of_days = 31
   Case 2
      number_of_days = 28
   Case 4, 6, 9, 11
      number_of_days = 30
End Select

Select Case: Second Form [Relational Test]

Select Case Expression
   Case Is relation :
      'one or more visual basic statements
   Case Is relation :
      'one or more visual basic statements
   Case Else :
      'one or more visual basic statements
End Select

EXAMPLE

Select Case marks
   Case Is < 50
      Result = "Fail"
   Case Is < 60
      Result = "Grade B"
   Case Is < 75
      Result = "Grade A"
   Case Else
      Result = "Grade A+"
End Select

Select Case: Third Format [Range Check]

Select Case Expression
   Case exp1 To exp2 :
      'one or more visual basic statements
   Case exp1 To exp2 :
      'one or more visual basic statements
   [Case Else :
      'one or more visual basic statements]
End Select

EXAMPLE

Select Case Age
   Case 2 To 4 : Print "PreNursery"
   Case 4 To 6 : Print "Kindergarden"
   Case 6 To 10 : Print "Primary"
   Case Else : Print "Others"
End Select

Iterative Constructs (Looping Structures)

Loop: A loop is a set of instructions which is repeated again and again in a program.
Types of Loops in VB:
Sentinel-controlled Loop Structures: repeat statements until a special value called sentinel value (or the terminating value) is reached.
Counter-controlled Loop Structures: repeat the set of statements until the value specified by the counter variable is reached.
VB offers broadly the following three types of looping structures:
1. For..Next
2. Do Loop (Do While..Loop, Do..Loop While, Do Until..Loop, Do..Loop Until)
3. While..Wend

For..Next Statement

Syntax:

For <counterVariable> = <start_val> To <end_val>
   Step <increment/decrement value>
   ' One or more VB Statements
Next <counterVariable>

This type of statement is used when the user knows in advance how many times the loop is going to be executed.

Do While..Loop

Syntax:

Do While <condition or boolean expression>
   ' One or more VB Statements
Loop

Do While loop is an entry controlled loop in which the condition is placed at the entry point.
This statement executes the statements specified in the body of the loop till the condition evaluates to true.
The loop may not be executed at all if the condition is initially false.

Do Loop While

Syntax:

Do
   One or more VB Statements
Loop While <condition or Boolean Expression>

Do Loop While is an exit controlled loop as the condition is placed at exit point.
The body of the loop is going to be executed at least once whether the condition evaluates to true or false.
Loop is executed as long as the result of the condition remains true.

Do Until loop

Syntax:

Do Until <condition or boolean expression>
   ' One or more VB Statements
Loop

Do Until loop is an entry controlled loop in which the condition is placed at the entry point.
This statement executes the statements specified in the body of the loop till the condition evaluates to true (that is, while it is false).
The loop may not be executed at all if the condition is initially true.

Do Loop Until

Syntax:

Do
   One or more VB Statements
Loop Until <condition or Boolean Expression>

Do Loop Until is an exit controlled loop as the condition is placed at exit point.
The body of the loop is going to be executed at least once whether the condition evaluates to true or false.
Loop is executed as long as the result of the condition remains false.

While..Wend loop

Syntax:

While <Condition>
   one or more vb statements
Wend

While..Wend loop is functionally equivalent to the Do While..Loop. It executes a set of VB statements till the condition evaluates to true.

Collections

Collection classes are specialized classes for data storage and retrieval.
These classes provide support for stacks, queues, lists, and hash tables.
Most collection classes implement the same interfaces.
Collection classes serve various purposes, such as allocating memory dynamically to elements and accessing a list of items on the basis of an index, etc.
These classes create collections of objects of the Object class, which is the base class for all data types in VB.Net.

Various Collection Classes and Their Usage

1. ArrayList
2. Hashtable
3. SortedList
4. Stack
5. Queue
6. BitArray

ArrayList

It represents an ordered collection of an object that can be indexed individually.
It is basically an alternative to an array.
However, unlike an array, you can add and remove items from a list at a specified position using an index and the array resizes itself automatically.
It also allows dynamic memory allocation, add, search and sort items in the list.

Hashtable

It uses a key to access the elements in the collection.
A hash table is used when you need to access elements by using a key, and you can identify a useful key value.
Each item in the hash table has a key/value pair.
The key is used to access the items in the collection.

SortedList

It uses a key as well as an index to access the items in a list.
A sorted list is a combination of an array and a hash table.
It contains a list of items that can be accessed using a key or an index.
If you access items using an index, it is an ArrayList, and if you access items using a key, it is a Hashtable.
The collection of items is always sorted by the key value.

Stack

It represents a last-in, first-out collection of object.
It is used when you need a last-in, first-out access of items.
When you add an item in the list, it is called pushing the item, and when you remove it, it is called popping the item.

Queue

It represents a first-in, first-out collection of object.
It is used when you need a first-in, first-out access of items.
When you add an item in the list, it is called enqueue, and when you remove an item, it is called dequeue.

BitArray

It represents an array of the binary representation using the values 1 and 0.
It is used when you need to store the bits but do not know the number of bits in advance.
You can access items from the BitArray collection by using an integer index, which starts from zero.

Free CBSE Study Guides: Computer Science .NET Technology

Comprehensive Study Resources for .NET Technology

Review targeted study resources for .NET Technology tailored for learners. Utilizing these structured notes and quick-revision tools ensures complete alignment with current CBSE evaluation standards.

Understanding Marking Schemes

Each resource draws directly from authorized textbooks to maintain academic accuracy. Evaluating solved examples allows students to master the formal presentation and answer-writing standards expected in upcoming school exams.

Complete Revision for Computer Science

For peak performance in upcoming evaluations, integrate official Computer Science sample papers directly into your study schedule. Follow up your revision by attempting online MCQ tests for .NET Technology to refine calculation speed and precision.

FAQs

Where can I find the most advanced study material for [current-page:node:field_board] [current-page:node:field_class] Computer Science for 2026-27?

The latest 2026-27 advanced study resources for Computer Science are available for free on StudiesToday.com which includes NCERT Exemplars, high-order thinking skills (HOTS) questions, and deep-dive concept summaries.

What does the 2026-27 Computer Science study package for [current-page:node:field_class] include?

Our exhaustive Computer Science package includes chapter wise revision notes, solved practice sheets, important formulas and Concept Maps to help in better understanding of all topics.

Is this study material enough for both [current-page:node:field_board] exams and competitive tests?

Yes. For , our resources have been developed to help you get better marks in school exams and also build fundamental strength needed for entrance tests including Competency Based learning.

How should [current-page:node:field_class] students use this Computer Science material for maximum marks?

in , students should use Active Recall method, read the concept summary, then solve the Important Questions section without looking at the answers and then check your answers.

Can I download [current-page:node:field_class] Computer Science study notes in PDF for offline use?

All Computer Science study materials are provided in mobile-friendly PDF. You can download and save them on your device.

Are the [current-page:node:field_class] Computer Science resources updated for the latest NEP guidelines?

Yes, our team has ensured that all Computer Science materials for are strictly aligned with the National Education Policy (NEP) 2020 and the latest 2026-27 syllabus.