SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

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

Similar to Loop control statements (20)

Chapter 9 - Loops in C++
Chapter 9 - Loops in C++Chapter 9 - Loops in C++
Chapter 9 - Loops in C++
Deepak Singh
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
Neeru Mittal
 
Managing input and output operations & Decision making and branching and looping
Managing input and output operations & Decision making and branching and loopingManaging input and output operations & Decision making and branching and looping
Managing input and output operations & Decision making and branching and looping
letheyabala
 
Lect3-C--EEB.pptx
Lect3-C--EEB.pptxLect3-C--EEB.pptx
Lect3-C--EEB.pptx
KIJAMALEGI
 
Xamarin: Branching and Looping
Xamarin: Branching and LoopingXamarin: Branching and Looping
Xamarin: Branching and Looping
Eng Teong Cheah
 
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdfPROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
JNTUK KAKINADA
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
PRN USM
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
Neeru Mittal
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
SzeChingChen
 
Python for Beginners(v2)
Python for Beginners(v2)Python for Beginners(v2)
Python for Beginners(v2)
Panimalar Engineering College
 
Operators
OperatorsOperators
Operators
Allah Ditta
 
Introduction to programming in C++ : Loop Structure.pptx
Introduction to programming in C++ : Loop Structure.pptxIntroduction to programming in C++ : Loop Structure.pptx
Introduction to programming in C++ : Loop Structure.pptx
ofeliacanaria1
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
Niket Chandrawanshi
 
Unit 2=Decision Control & Looping Statements.pdf
Unit 2=Decision Control & Looping Statements.pdfUnit 2=Decision Control & Looping Statements.pdf
Unit 2=Decision Control & Looping Statements.pdf
Dr. Ambedkar Institute of Technology, Bangalore 56
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
Vladislav Hadzhiyski
 
Chapter 5 java
Chapter 5 javaChapter 5 java
Chapter 5 java
Ahmad sohail Kakar
 
Introduction& Overview-to-C++_programming.pptx
Introduction& Overview-to-C++_programming.pptxIntroduction& Overview-to-C++_programming.pptx
Introduction& Overview-to-C++_programming.pptx
divyadhanwani67
 
Introduction to C++ programming language
Introduction to C++ programming languageIntroduction to C++ programming language
Introduction to C++ programming language
divyadhanwani67
 
Vb.net ii
Vb.net iiVb.net ii
Vb.net ii
argusacademy
 
Loops c++
Loops c++Loops c++
Loops c++
Shivani Singh
 
Chapter 9 - Loops in C++
Chapter 9 - Loops in C++Chapter 9 - Loops in C++
Chapter 9 - Loops in C++
Deepak Singh
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
Neeru Mittal
 
Managing input and output operations & Decision making and branching and looping
Managing input and output operations & Decision making and branching and loopingManaging input and output operations & Decision making and branching and looping
Managing input and output operations & Decision making and branching and looping
letheyabala
 
Lect3-C--EEB.pptx
Lect3-C--EEB.pptxLect3-C--EEB.pptx
Lect3-C--EEB.pptx
KIJAMALEGI
 
Xamarin: Branching and Looping
Xamarin: Branching and LoopingXamarin: Branching and Looping
Xamarin: Branching and Looping
Eng Teong Cheah
 
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdfPROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
JNTUK KAKINADA
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
PRN USM
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
Neeru Mittal
 
Introduction to programming in C++ : Loop Structure.pptx
Introduction to programming in C++ : Loop Structure.pptxIntroduction to programming in C++ : Loop Structure.pptx
Introduction to programming in C++ : Loop Structure.pptx
ofeliacanaria1
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
Vladislav Hadzhiyski
 
Introduction& Overview-to-C++_programming.pptx
Introduction& Overview-to-C++_programming.pptxIntroduction& Overview-to-C++_programming.pptx
Introduction& Overview-to-C++_programming.pptx
divyadhanwani67
 
Introduction to C++ programming language
Introduction to C++ programming languageIntroduction to C++ programming language
Introduction to C++ programming language
divyadhanwani67
 
Ad

More from Jaya Kumari (18)

Python data type
Python data typePython data type
Python data type
Jaya Kumari
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Jaya Kumari
 
Variables in python
Variables in pythonVariables in python
Variables in python
Jaya Kumari
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
Jaya Kumari
 
Oops
OopsOops
Oops
Jaya Kumari
 
Inheritance
InheritanceInheritance
Inheritance
Jaya Kumari
 
Overloading
OverloadingOverloading
Overloading
Jaya Kumari
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
Jaya 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.net
Jaya Kumari
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
Jaya Kumari
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespace
Jaya Kumari
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net
Jaya Kumari
 
Jsp basic
Jsp basicJsp basic
Jsp basic
Jaya Kumari
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
Jaya Kumari
 
Sgml and xml
Sgml and xmlSgml and xml
Sgml and xml
Jaya Kumari
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
Jaya Kumari
 
Html form
Html formHtml form
Html form
Jaya Kumari
 
Html Concept
Html ConceptHtml Concept
Html Concept
Jaya Kumari
 
Python data type
Python data typePython data type
Python data type
Jaya Kumari
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Jaya Kumari
 
Variables in python
Variables in pythonVariables in python
Variables in python
Jaya Kumari
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
Jaya Kumari
 
Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
Jaya 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.net
Jaya Kumari
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
Jaya Kumari
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespace
Jaya 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 Basic
Jaya Kumari
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
Jaya Kumari
 
Ad

Recently uploaded (20)

To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 

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