SlideShare a Scribd company logo
1 of 14
VB.NET:- Loop Statements
BCA -501
2
Content
 Introduction
 Looping Statement
 Advantages of Looping Statements
 Types of Looping Statements
3
What is Looping Statement?
 A Loop is used to repeat the same process multiple times until it meets the
specified condition in a program.
 By using a loop in a program, a programmer can repeat any number of statements
up to the desired number of repetitions.
 A loop also provides the suitability to a programmer to repeat the statement in a
program according to the requirement.
 A loop is also used to reduce the program complexity, easy to understand, and
easy to debug.
4
Advantages of Looping Statements
 It provides code iteration functionality in a program.
 It executes the statement until the specified condition is true.
 It helps in reducing the size of the code.
 It reduces compile time.
5
Types of Loop Constructs
 VB.NET supports following types of loop:
1. While..End While
2. Do…..Loop
3. For … Next
4. For Each… Next
6
While… End Loop Constructs
 The 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.
 If the condition is true, the body of the while
loop is executed. This process of repeated
execution of the body continues until the
condition is not false. And if the condition is
false, control is transferred out of the loop.
7
While Loop-Syntax & Example
Example:
Imports System
Module while_number
Sub Main()
'declare x as an integer variable
Dim x As Integer
x = 1
' Use While End condition
While x <= 10
'If the condition is true, the statement will be executed.
Console.WriteLine(" Number {0}", x)
x = x + 1 ' Statement that change the value of the
condition
End While
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module
Syntax:
While [condition]
[ Statement to be executed ]
End While
8
Do-While Loop
 In VB.NET, Do While loop is used to
execute blocks of statements in the
program, as long as the condition
remains true.
 It is similar to the While End Loop,
but there is slight difference between
them.
 The while loop initially checks the
defined condition, if the condition
becomes true, the while loop's
statement is executed. Whereas in
the Do loop, is opposite of the while
loop, it means that it executes the Do
statements, and then it checks the
condition.
9
Do-While Loop
Example:
Imports System
Module Do_loop
Sub Main()
' Initializatio and Declaration of variable i
Dim i As Integer = 1
Do
' Executes the following Statement
Console.WriteLine(" Value of variable I is : {0}", i)
i = i + 1 'Increment the variable i by 1
Loop While i <= 10 ' Define the While Condition
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module
Syntax:
Do
[ Statements to be executed]
Loop While Boolean_expression
// or
Do
[Statement to be executed]
Loop Until Boolean_expression
10
For…Next Loop
 A 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.
11
For Loop-Syntax
For: It is the keyword that is present at the beginning of the definition.
variable_name: It is a variable name, which is required in the For loop Statement. The value of the variable
determines when to exit from the For-Next loop, and the value should only be a numeric.
[Data Type]: It represents the Data Type of the variable_name.
start To end: The start and end are the two important parameters representing the initial and final values of
the variable_name. These parameters are helpful while the execution begins, the initial value of the variable is set by
the start. Before the completion of each repetition, the variable's current value is compared with the end value. And if
the value of the variable is less than the end value, the execution continues until the variable's current value is greater
than the end value. And if the value is exceeded, the loop is terminated.
Step: A step parameter is used to determine by which the counter value of a variable is increased or decreased after
each iteration in a program. If the counter value is not specified; It uses 1 as the default value.
Statements: A statement can be a single statement or group of statements that execute during the completion of
each iteration in a loop.
Next: In VB.NET a Next is a keyword that represents the end of the For loop's
Syntax:
For variable_name As [ DataType ] = start To end [ Step step ]
[ Statements to be executed ]
Next
12
For Loop- Example
Imports System
Module Number
Sub Main()
' It is a simple print statement, and 'vbCrLf' is used to jump in the next line.
Console.Write(" The number starts from 1 to 10 " & vbCrLf)
' declare and initialize variable i
For i As Integer = 1 To 10 Step 1
' if the condition is true, the following statement will be executed
Console.WriteLine(" Number is {0} ", i)
' after completion of each iteration, next will update the variable counter
Next
Console.WriteLine(" Press any key to exit... ")
Console.ReadKey()
End Sub
End Module
13
For…Each…Next Loop
 In the VB.NET, 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.
 For Each loop is used to read each
element from the collection object or an
array.
 The Data Type represents the type of the
variable, and var_name is the name of the
variable to access elements from
the array or collection object so that it can
be used in the body of For Each loop.
14
For Each Loop-Syntax & Example
Syntax:
For Each var_name As [ DataType ] In Collection_Object
[ Statements to be executed]
Next
Imports System
Module For_Each_loop
Sub Main()
'declare and initialize an array as integer
Dim An_array() As Integer = {1, 2, 3, 4, 5}
Dim i As Integer 'Declare i as Integer
For Each i In An_array
Console.WriteLine(" Value of i is {0}", i)
Next
Console.WriteLine("Press any key to exit...")
Console.ReadLine()
End Sub
End Module

More Related Content

What's hot

Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programmingRabin BK
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__elseeShikshak
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingMegha V
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in JavaNiloy Saha
 
Loop in C Properties & Applications
Loop in C Properties & ApplicationsLoop in C Properties & Applications
Loop in C Properties & ApplicationsEmroz Sardar
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in javaAtul Sehdev
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statementsjyoti_lakhani
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & RecoveryAkhil Kaushik
 
Conditional statement
Conditional statementConditional statement
Conditional statementMaxie Santos
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in JavaJin Castor
 
Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 
Translation of expression(copmiler construction)
Translation of expression(copmiler construction)Translation of expression(copmiler construction)
Translation of expression(copmiler construction)IrtazaAfzal3
 
Jumping statements
Jumping statementsJumping statements
Jumping statementsSuneel Dogra
 
Control structures in java
Control structures in javaControl structures in java
Control structures in javaVINOTH R
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithmrajkumar1631010038
 

What's hot (20)

Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Iteration
IterationIteration
Iteration
 
Control statement-Selective
Control statement-SelectiveControl statement-Selective
Control statement-Selective
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Loop in C Properties & Applications
Loop in C Properties & ApplicationsLoop in C Properties & Applications
Loop in C Properties & Applications
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
Conditional statement
Conditional statementConditional statement
Conditional statement
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Translation of expression(copmiler construction)
Translation of expression(copmiler construction)Translation of expression(copmiler construction)
Translation of expression(copmiler construction)
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
 

Similar to Looping statements

BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETUjwala Junghare
 
Unit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUnit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUjwala Junghare
 
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJanCarlBriones2
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition StructureShahzu2
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYRajeshkumar Reddy
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio) rnkhan
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)rnkhan
 
Loop control statements
Loop control statementsLoop control statements
Loop control statementsJaya Kumari
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3Isham Rashik
 
Control structures ii
Control structures ii Control structures ii
Control structures ii Ahmad Idrees
 
Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Blue Elephant Consulting
 

Similar to Looping statements (20)

BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
Unit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUnit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptx
 
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptx
 
VB Script Overview
VB Script OverviewVB Script Overview
VB Script Overview
 
Vb (2)
Vb (2)Vb (2)
Vb (2)
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition Structure
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio)
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Loop control statements
Loop control statementsLoop control statements
Loop control statements
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Final requirement
Final requirementFinal requirement
Final requirement
 
Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2Intro To C++ - Class 10 - Control Statements: Part 2
Intro To C++ - Class 10 - Control Statements: Part 2
 

More from Jaya Kumari

Python data type
Python data typePython data type
Python data typeJaya Kumari
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonJaya Kumari
 
Variables in python
Variables in pythonVariables in python
Variables in pythonJaya Kumari
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by pythonJaya Kumari
 
Decision statements
Decision statementsDecision statements
Decision statementsJaya Kumari
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.netJaya Kumari
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NETJaya Kumari
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netJaya Kumari
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.netJaya Kumari
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespaceJaya Kumari
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net Jaya Kumari
 
Java script Basic
Java script BasicJava script Basic
Java script BasicJaya Kumari
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script AdvanceJaya Kumari
 

More from Jaya Kumari (20)

Python data type
Python data typePython data type
Python data type
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Variables in python
Variables in pythonVariables in python
Variables in python
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
 
Oops
OopsOops
Oops
 
Inheritance
InheritanceInheritance
Inheritance
 
Overloading
OverloadingOverloading
Overloading
 
Decision statements
Decision statementsDecision statements
Decision statements
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespace
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net
 
Jsp basic
Jsp basicJsp basic
Jsp basic
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Sgml and xml
Sgml and xmlSgml and xml
Sgml and xml
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
 
Html form
Html formHtml form
Html form
 
Html Concept
Html ConceptHtml Concept
Html Concept
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 

Looping statements

  • 2. 2 Content  Introduction  Looping Statement  Advantages of Looping Statements  Types of Looping Statements
  • 3. 3 What is Looping Statement?  A Loop is used to repeat the same process multiple times until it meets the specified condition in a program.  By using a loop in a program, a programmer can repeat any number of statements up to the desired number of repetitions.  A loop also provides the suitability to a programmer to repeat the statement in a program according to the requirement.  A loop is also used to reduce the program complexity, easy to understand, and easy to debug.
  • 4. 4 Advantages of Looping Statements  It provides code iteration functionality in a program.  It executes the statement until the specified condition is true.  It helps in reducing the size of the code.  It reduces compile time.
  • 5. 5 Types of Loop Constructs  VB.NET supports following types of loop: 1. While..End While 2. Do…..Loop 3. For … Next 4. For Each… Next
  • 6. 6 While… End Loop Constructs  The 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.  If the condition is true, the body of the while loop is executed. This process of repeated execution of the body continues until the condition is not false. And if the condition is false, control is transferred out of the loop.
  • 7. 7 While Loop-Syntax & Example Example: Imports System Module while_number Sub Main() 'declare x as an integer variable Dim x As Integer x = 1 ' Use While End condition While x <= 10 'If the condition is true, the statement will be executed. Console.WriteLine(" Number {0}", x) x = x + 1 ' Statement that change the value of the condition End While Console.WriteLine(" Press any key to exit...") Console.ReadKey() End Sub End Module Syntax: While [condition] [ Statement to be executed ] End While
  • 8. 8 Do-While Loop  In VB.NET, Do While loop is used to execute blocks of statements in the program, as long as the condition remains true.  It is similar to the While End Loop, but there is slight difference between them.  The while loop initially checks the defined condition, if the condition becomes true, the while loop's statement is executed. Whereas in the Do loop, is opposite of the while loop, it means that it executes the Do statements, and then it checks the condition.
  • 9. 9 Do-While Loop Example: Imports System Module Do_loop Sub Main() ' Initializatio and Declaration of variable i Dim i As Integer = 1 Do ' Executes the following Statement Console.WriteLine(" Value of variable I is : {0}", i) i = i + 1 'Increment the variable i by 1 Loop While i <= 10 ' Define the While Condition Console.WriteLine(" Press any key to exit...") Console.ReadKey() End Sub End Module Syntax: Do [ Statements to be executed] Loop While Boolean_expression // or Do [Statement to be executed] Loop Until Boolean_expression
  • 10. 10 For…Next Loop  A 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.
  • 11. 11 For Loop-Syntax For: It is the keyword that is present at the beginning of the definition. variable_name: It is a variable name, which is required in the For loop Statement. The value of the variable determines when to exit from the For-Next loop, and the value should only be a numeric. [Data Type]: It represents the Data Type of the variable_name. start To end: The start and end are the two important parameters representing the initial and final values of the variable_name. These parameters are helpful while the execution begins, the initial value of the variable is set by the start. Before the completion of each repetition, the variable's current value is compared with the end value. And if the value of the variable is less than the end value, the execution continues until the variable's current value is greater than the end value. And if the value is exceeded, the loop is terminated. Step: A step parameter is used to determine by which the counter value of a variable is increased or decreased after each iteration in a program. If the counter value is not specified; It uses 1 as the default value. Statements: A statement can be a single statement or group of statements that execute during the completion of each iteration in a loop. Next: In VB.NET a Next is a keyword that represents the end of the For loop's Syntax: For variable_name As [ DataType ] = start To end [ Step step ] [ Statements to be executed ] Next
  • 12. 12 For Loop- Example Imports System Module Number Sub Main() ' It is a simple print statement, and 'vbCrLf' is used to jump in the next line. Console.Write(" The number starts from 1 to 10 " & vbCrLf) ' declare and initialize variable i For i As Integer = 1 To 10 Step 1 ' if the condition is true, the following statement will be executed Console.WriteLine(" Number is {0} ", i) ' after completion of each iteration, next will update the variable counter Next Console.WriteLine(" Press any key to exit... ") Console.ReadKey() End Sub End Module
  • 13. 13 For…Each…Next Loop  In the VB.NET, 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.  For Each loop is used to read each element from the collection object or an array.  The Data Type represents the type of the variable, and var_name is the name of the variable to access elements from the array or collection object so that it can be used in the body of For Each loop.
  • 14. 14 For Each Loop-Syntax & Example Syntax: For Each var_name As [ DataType ] In Collection_Object [ Statements to be executed] Next Imports System Module For_Each_loop Sub Main() 'declare and initialize an array as integer Dim An_array() As Integer = {1, 2, 3, 4, 5} Dim i As Integer 'Declare i as Integer For Each i In An_array Console.WriteLine(" Value of i is {0}", i) Next Console.WriteLine("Press any key to exit...") Console.ReadLine() End Sub End Module