OOP Lesson 1
OOP Lesson 1
OOP Lesson 1
3 – O.O.P
Vb.Net Looping Statements
• For Next Loop - is used to repeatedly execute a sequence of code or a block of
code until a given condition is satisfied. A For loop is useful in such a case when
we know how many times a block of code has to be executed. In VB.NET, the For
loop is also known as For Next Loop.
Vb.Net Looping Statements
• For Each loop is used to iterate block of statements in an array or collection
objects. Using For Each loop, we can easily work with collection objects such as
lists, arrays, etc., to execute each element of an array or in a collection. And
when iteration through each element in the array or collection is complete, the
control transferred to the next statement to end the loop.
Vb.Net Looping Statements
• Do While loop is used to execute blocks of statements in the program, as long
as the condition remains true.
Vb.Net Looping Statements
• While End loop is used to execute blocks of code or statements in a program,
as long as the given condition is true. It is useful when the number of executions
of a block is not known. It is also known as an entry-controlled loop statement,
which means it initially checks all loop conditions.
What is OOP?
• Stands for Object Oriented Programming.
• OOP is a computer programming model that organizes
software design around data, or objects, rather than
functions and logic. An object can be defined as a data field
that has unique attributes and behavior. It also focuses on
the objects that developers want to manipulate rather than
the logic required to manipulate them. This approach to
programming is well-suited for programs that are large,
complex and actively updated or maintained.
What is a Sub?
• A Sub is a procedure that performs a task and then returns
control to the calling code, but it does not return a value to
the calling code. Each time the procedure is called, its
statements are executed, starting with the first executable
statement after the Sub statement and ending with the first
End Sub or Exit Sub.
• Sub Declaration Syntax
• Example
What is a Function
• A Function is a series of statements enclosed by the Function
and End Function statements. The Function procedure
performs a task and then returns control to the calling code.
When it returns control, it also returns a value to the calling
code. Each time the procedure is called, its statements run,
starting with the first executable statement after the
Function statement and ending with the first End Function,
Exit Function or Return statement encountered.
• Function Declaration Syntax
• Example
Function Returning Values
• Using Return keyword - It uses the Return Keyword to specify
the return value, and returns control immediately to the
calling program. The following example illustrates this.
• Using own function name - It assigns a value to its own function name in one
or more statements of the procedure. Control does not return to the
calling program until an Exit Function or End Function Keyword is
executed. The following example illustrates this.
The advantage of assigning the return value to the function name is that
control does not return from the procedure until it encounters an Exit
Function or End function. This allows you to assign a preliminary value and
adjust it later if necessary.
Recursive function
• a recursive function is a function that solves a problem by
solving smaller instances of the same problem. This
technique is commonly used in programming to solve
problems that can be broken down into simpler, similar
subproblems.
Classes
• A Class is a group of different data members or objects with the
same properties, processes, events of an object, and general
relationships to other member functions.
• We can create a class using the Class keyword, followed by the
class name. And the body of the class ended with the statement
End Class.
[ Access_Specifier ] Class ClassName
' Data Members or Variable Declaration
' Methods Name
' Statement to be executed
End Class
Objects
• Objects are the basic run-time units of a class. Once a class is
defined, we can create any number of objects related to the
class to access the defined properties and methods.