SlideShare a Scribd company logo
3
Most read
5
Most read
10
Most read
VB.NET:- Loop Control Statements
BCA -501
2
Content
 Introduction
 Exit statement
 Continue Statement
 Goto Statement
3
What is Loop Control Statements?
 Loop control statements change execution from its normal sequence. When
execution leaves a scope, all automatic objects that were created in that scope are
destroyed.
 VB.Net provides the following control statements:
1. Exit Statement
2. Continue Statement
3. Goto Statement
4
Exit Statements
 The Exit statement transfers the control from a procedure or block immediately
to the statement following the procedure call or the block definition.
 It terminates the loop, procedure, try block or the select block from where it is
called.
 If you are using nested loops (i.e., one loop inside another loop), the Exit
statement will stop the execution of the innermost loop and start executing the
next line of code after the block.
 Generally, the Exit statement is written along with a condition. If
the Exit condition is true inside the loop, it exits from the loop and control
transfer to the next statement, followed by the loop. And if the Exit condition
fails for the first time, it will not check any statement inside the loop
and terminates the program.
5
Exit Statements Example
Syntax:
Exit { Do | For | Function | Property | Select | Sub | Try | While }
Imports System
Module Exit_While
Sub Main()
Dim count As Integer = 1
While (count < 10)
If count = 5 Then
Exit While ' terminate the While loop
End If
Console.WriteLine(" Value of Count is : {0}", count)
count = count + 1
End While
Console.WriteLine(" Exit from the While loop when count = {0}", count)
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module
6
Continue Statements
 The Continue statement causes the loop to skip the remainder of its body and
immediately retest its condition prior to reiterating.
 It works somewhat like the Exit statement. Instead of forcing termination, it
forces the next iteration of the loop to take place, skipping any code in between.
 For the For...Next loop, Continue statement causes the conditional test and
increment portions of the loop to execute. For the While and Do...While loops,
continue statement causes the program control to pass to the conditional tests.
 The main difference between the Exit and a Continue Statement is that the Exit
Statement is used to exit or terminate the loop's execution process. In contrast,
the Continue Statement is used to Skip the particular iteration and continue with
the next iteration without ending the loop.
7
Continue Statements Example
Syntax:
Continue { Do | For | While }
Imports System
Module Continue_While
Sub Main()
Dim i As Integer = 10
While i < 20
If i = 14 Then
Console.WriteLine(" Skipped number is {0}", i)
i += 1 ' skip the define iteration
Continue While
End If
Console.WriteLine(" Value of i is {0}", i)
i += 1 ' Update the variable i by 1
End While
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module
8
Goto Statements
 In VB.NET, the GoTo statement is known as a jump statement.
 The GoTo statement transfers control unconditionally to a specified line in a
procedure.
 The GoTo statement uses labels that must be a valid identifier. The GoTo
statement can be used in Select case, decision control statements, and loops.
9
Goto statements in if..else example
Imports System
Module Goto_Statement
Sub Main()
Dim num As Integer
Console.WriteLine(" Enter the number :")
num = Console.ReadLine ' Accept a number from the user
If (num Mod 2 = 0) Then
GoTo even ' Jump to even label
Else
GoTo odd ' Jump to odd label
End If
odd:
Console.WriteLine(" It is an Odd number")
even:
Console.WriteLine(" It is an Even number ")
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module
10
Goto statements in for..next example
Imports System
Module Goto_For
Sub Main()
Dim i, n As Integer, Sum As Integer = 0
For i = 1 To 10
Console.WriteLine(" Value of i is {0}", i)
Sum = Sum + i 'At each iteration the value of i added to Sum
If i = 5 Then
n = i 'Assign i to n GoTo total_sum ' Jump to total_sum
End If
Next
total_sum:
Console.WriteLine(" Total sum is {0}", Sum)
Console.WriteLine(" GoTo Encounter, when value of i = {0}", n)
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module

More Related Content

PPTX
Decision statements
Jaya Kumari
 
PPTX
Looping statements
Jaya Kumari
 
PPTX
Operators used in vb.net
Jaya Kumari
 
PPT
Control structures ii
Ahmad Idrees
 
PPTX
BSc. III Unit iii VB.NET
Ujwala Junghare
 
PPTX
Java Decision Control
Jayfee Ramos
 
PPTX
Control statements in java
Madishetty Prathibha
 
PPT
Java control flow statements
Future Programming
 
Decision statements
Jaya Kumari
 
Looping statements
Jaya Kumari
 
Operators used in vb.net
Jaya Kumari
 
Control structures ii
Ahmad Idrees
 
BSc. III Unit iii VB.NET
Ujwala Junghare
 
Java Decision Control
Jayfee Ramos
 
Control statements in java
Madishetty Prathibha
 
Java control flow statements
Future Programming
 

What's hot (20)

PPTX
Control structures in java
VINOTH R
 
PPTX
Java loops for, while and do...while
Jayfee Ramos
 
PPTX
Program control statements in c#
Dr.Neeraj Kumar Pandey
 
PPT
Control structures in C++ Programming Language
Ahmad Idrees
 
PPTX
C++ decision making
Zohaib Ahmed
 
PPT
04 control structures 1
Jomel Penalba
 
PPTX
C# conditional branching statement
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
07 flow control
dhrubo kayal
 
DOC
Conditional statements in vb script
Nilanjan Saha
 
PPTX
Control flow statements in java
yugandhar vadlamudi
 
PPTX
Understand Decision structures in c++ (cplusplus)
Muhammad Tahir Bashir
 
PPTX
Flow Control (C#)
Bhushan Mulmule
 
PPTX
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
PPTX
Data structures vb
nicky_walters
 
DOC
Jumping statements
Suneel Dogra
 
PDF
Control statements
Kanwalpreet Kaur
 
PPT
Control structures i
Ahmad Idrees
 
PPTX
Chapter 2 : Programming with Java Statements
It Academy
 
PPT
Conditional Loops Python
primeteacher32
 
PPTX
Vb decision making statements
pragya ratan
 
Control structures in java
VINOTH R
 
Java loops for, while and do...while
Jayfee Ramos
 
Program control statements in c#
Dr.Neeraj Kumar Pandey
 
Control structures in C++ Programming Language
Ahmad Idrees
 
C++ decision making
Zohaib Ahmed
 
04 control structures 1
Jomel Penalba
 
C# conditional branching statement
baabtra.com - No. 1 supplier of quality freshers
 
07 flow control
dhrubo kayal
 
Conditional statements in vb script
Nilanjan Saha
 
Control flow statements in java
yugandhar vadlamudi
 
Understand Decision structures in c++ (cplusplus)
Muhammad Tahir Bashir
 
Flow Control (C#)
Bhushan Mulmule
 
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
Data structures vb
nicky_walters
 
Jumping statements
Suneel Dogra
 
Control statements
Kanwalpreet Kaur
 
Control structures i
Ahmad Idrees
 
Chapter 2 : Programming with Java Statements
It Academy
 
Conditional Loops Python
primeteacher32
 
Vb decision making statements
pragya ratan
 
Ad

Similar to Loop control statements (20)

PPT
Vb scripting
Brad Winborg
 
PPTX
CONTROL STRUCTURE IN VB
classall
 
PPTX
Vb.net (loop structure)
Abhishek Pachisia
 
PPT
Vb (2)
Rajeev Sharan
 
PPTX
Loops in C
Kamal Acharya
 
PDF
Conditional Statements & Loops
simmis5
 
PPTX
Operators
Allah Ditta
 
PDF
VB PPT by ADI PART3.pdf
Prof. Dr. K. Adisesha
 
PDF
VB PPT by ADI PART3.pdf
AdiseshaK
 
PDF
Do...Loop
Muhammad Al Fatih
 
PDF
Loops
EMAD ALHOTHLY
 
PDF
Vb script tutorial
Abhishek Kesharwani
 
DOCX
Vb script tutorial
Abhishek Kesharwani
 
PPTX
VB(unit1).pptx
sudharsanm56
 
PPTX
Unit IV Array in VB.Net.pptx
Ujwala Junghare
 
PDF
C sharp chap4
Mukesh Tekwani
 
PPTX
Looping statement in vb.net
ilakkiya
 
PPTX
Introduction to VB.NET - UP SITF
John Patrick Oliveros
 
PDF
Chapter 9 - Loops in C++
Deepak Singh
 
PPSX
Control Structures in Visual Basic
Tushar Jain
 
Vb scripting
Brad Winborg
 
CONTROL STRUCTURE IN VB
classall
 
Vb.net (loop structure)
Abhishek Pachisia
 
Loops in C
Kamal Acharya
 
Conditional Statements & Loops
simmis5
 
Operators
Allah Ditta
 
VB PPT by ADI PART3.pdf
Prof. Dr. K. Adisesha
 
VB PPT by ADI PART3.pdf
AdiseshaK
 
Vb script tutorial
Abhishek Kesharwani
 
Vb script tutorial
Abhishek Kesharwani
 
VB(unit1).pptx
sudharsanm56
 
Unit IV Array in VB.Net.pptx
Ujwala Junghare
 
C sharp chap4
Mukesh Tekwani
 
Looping statement in vb.net
ilakkiya
 
Introduction to VB.NET - UP SITF
John Patrick Oliveros
 
Chapter 9 - Loops in C++
Deepak Singh
 
Control Structures in Visual Basic
Tushar Jain
 
Ad

More from Jaya Kumari (18)

PPTX
Python data type
Jaya Kumari
 
PPTX
Introduction to python
Jaya Kumari
 
PPTX
Variables in python
Jaya Kumari
 
PPTX
Basic syntax supported by python
Jaya Kumari
 
PPTX
Oops
Jaya Kumari
 
PPTX
Inheritance
Jaya Kumari
 
PPTX
Overloading
Jaya Kumari
 
PPTX
Variable and constants in Vb.NET
Jaya Kumari
 
PPTX
Keywords, identifiers and data type of vb.net
Jaya Kumari
 
PPTX
Introduction to vb.net
Jaya Kumari
 
PPTX
Frame class library and namespace
Jaya Kumari
 
PPTX
Introduction to .net
Jaya Kumari
 
PPTX
Jsp basic
Jaya Kumari
 
PPTX
Java script Basic
Jaya Kumari
 
PPTX
Sgml and xml
Jaya Kumari
 
PPTX
Java script Advance
Jaya Kumari
 
PPTX
Html form
Jaya Kumari
 
PPTX
Html Concept
Jaya Kumari
 
Python data type
Jaya Kumari
 
Introduction to python
Jaya Kumari
 
Variables in python
Jaya Kumari
 
Basic syntax supported by python
Jaya Kumari
 
Inheritance
Jaya Kumari
 
Overloading
Jaya Kumari
 
Variable and constants in Vb.NET
Jaya Kumari
 
Keywords, identifiers and data type of vb.net
Jaya Kumari
 
Introduction to vb.net
Jaya Kumari
 
Frame class library and namespace
Jaya Kumari
 
Introduction to .net
Jaya Kumari
 
Jsp basic
Jaya Kumari
 
Java script Basic
Jaya Kumari
 
Sgml and xml
Jaya Kumari
 
Java script Advance
Jaya Kumari
 
Html form
Jaya Kumari
 
Html Concept
Jaya Kumari
 

Recently uploaded (20)

PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Virus sequence retrieval from NCBI database
yamunaK13
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 

Loop control statements

  • 1. VB.NET:- Loop Control Statements BCA -501
  • 2. 2 Content  Introduction  Exit statement  Continue Statement  Goto Statement
  • 3. 3 What is Loop Control Statements?  Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.  VB.Net provides the following control statements: 1. Exit Statement 2. Continue Statement 3. Goto Statement
  • 4. 4 Exit Statements  The Exit statement transfers the control from a procedure or block immediately to the statement following the procedure call or the block definition.  It terminates the loop, procedure, try block or the select block from where it is called.  If you are using nested loops (i.e., one loop inside another loop), the Exit statement will stop the execution of the innermost loop and start executing the next line of code after the block.  Generally, the Exit statement is written along with a condition. If the Exit condition is true inside the loop, it exits from the loop and control transfer to the next statement, followed by the loop. And if the Exit condition fails for the first time, it will not check any statement inside the loop and terminates the program.
  • 5. 5 Exit Statements Example Syntax: Exit { Do | For | Function | Property | Select | Sub | Try | While } Imports System Module Exit_While Sub Main() Dim count As Integer = 1 While (count < 10) If count = 5 Then Exit While ' terminate the While loop End If Console.WriteLine(" Value of Count is : {0}", count) count = count + 1 End While Console.WriteLine(" Exit from the While loop when count = {0}", count) Console.WriteLine(" Press any key to exit...") Console.ReadKey() End Sub End Module
  • 6. 6 Continue Statements  The Continue statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.  It works somewhat like the Exit statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between.  For the For...Next loop, Continue statement causes the conditional test and increment portions of the loop to execute. For the While and Do...While loops, continue statement causes the program control to pass to the conditional tests.  The main difference between the Exit and a Continue Statement is that the Exit Statement is used to exit or terminate the loop's execution process. In contrast, the Continue Statement is used to Skip the particular iteration and continue with the next iteration without ending the loop.
  • 7. 7 Continue Statements Example Syntax: Continue { Do | For | While } Imports System Module Continue_While Sub Main() Dim i As Integer = 10 While i < 20 If i = 14 Then Console.WriteLine(" Skipped number is {0}", i) i += 1 ' skip the define iteration Continue While End If Console.WriteLine(" Value of i is {0}", i) i += 1 ' Update the variable i by 1 End While Console.WriteLine(" Press any key to exit...") Console.ReadKey() End Sub End Module
  • 8. 8 Goto Statements  In VB.NET, the GoTo statement is known as a jump statement.  The GoTo statement transfers control unconditionally to a specified line in a procedure.  The GoTo statement uses labels that must be a valid identifier. The GoTo statement can be used in Select case, decision control statements, and loops.
  • 9. 9 Goto statements in if..else example Imports System Module Goto_Statement Sub Main() Dim num As Integer Console.WriteLine(" Enter the number :") num = Console.ReadLine ' Accept a number from the user If (num Mod 2 = 0) Then GoTo even ' Jump to even label Else GoTo odd ' Jump to odd label End If odd: Console.WriteLine(" It is an Odd number") even: Console.WriteLine(" It is an Even number ") Console.WriteLine(" Press any key to exit...") Console.ReadKey() End Sub End Module
  • 10. 10 Goto statements in for..next example Imports System Module Goto_For Sub Main() Dim i, n As Integer, Sum As Integer = 0 For i = 1 To 10 Console.WriteLine(" Value of i is {0}", i) Sum = Sum + i 'At each iteration the value of i added to Sum If i = 5 Then n = i 'Assign i to n GoTo total_sum ' Jump to total_sum End If Next total_sum: Console.WriteLine(" Total sum is {0}", Sum) Console.WriteLine(" GoTo Encounter, when value of i = {0}", n) Console.WriteLine(" Press any key to exit...") Console.ReadKey() End Sub End Module