Visual Basic.net L6
Visual Basic.net L6
Those statements, which are used to execute a set of statements again & again until
the given condition remains TRUE, are known as LOOPING STATEMENTS.
In another word, we can also say that these statements are used to repeat a certain task
until a certain period. That‘s why; it is also called REPETATIVE STATEMENTS or
ITERATIVE STATEMENT.
1. FOR – LOOP
2. WHILE – LOOP
3. DO – WHILE – LOOP
4. DO – UNTIL LOOP
5. DO – LOOP – WHILE
6. DO – LOOP- UNTIL
7. FOR EACH
1. FOR LOOP: -
It is looping statement which can repeat the set statements written within its body until
the given condition remains true.
Syntax: -
For variable = initial_value To final_value STEP <step_value>
Statement
-------------
-------------
Next variable
The Initial value indicates that from which value the loop will be started.
The Final value indicates that until which value, the loop will be repeated.
The STEP is the keyword and step value indicates that by which values the
looping variable is increased or decreased after each repetition. If it is not mentioned
than the FOR – LOOP variable is increased by 1 by default.
2. WHILE LOOP:-
It is also looping statement, which can repeat the statements until some
condition is satisfied.
Syntax: -
While (condition)
Statement
----------------
----------------
Increment/ Decrement part
Wend
The initial value of WHILE LOOP variable must be assigned above the WHILE
LOOP. The condition is mentioned with the loop, which specifies that how much
times the loop will be repeated.
3. DO – WHILE- LOOP:-
It is also looping statement, which is same as the WHILE – LOOP. But the difference
between WHILE - LOOP and DO – WHILE LOOP is that WHILE – LOOP cannot
be terminated before reaching on given condition but the DO – WHILE LOOP can be
terminated on some condition before reaching on given condition.
Syntax: -
Do while (condition)
Statement
----------------
----------------
Increment/Decrement part
Loop
4. DO – UNTIL- LOOP:-
It is also a looping statement of DO – LOOP series. It checks the condition for
falsity. It means, it checks the condition in negative and executes the body unless and
until the given condition evaluates to false.
Syntax: -
Do until (condition)
Statement
----------------
----------------
Increment/Decrement
Loop
5. DO - LOOP - WHILE:-
It is also a looping statement which must executes the statements at least once. Like
WHILE – LOOP and DO – WHILE – LOOP, it is also check the condition for true &
repeats the body unless and until, the given condition remains TRUE.
Syntax: -
Do
Statement
----------------
----------------
Increment/Decrement
Loop While (condition)
6. DO - LOOP - UNTIL:-
It is also a looping statement which must executes the statements at least once. But, it
checks the condition for falsity. That is, it repeats the statement unless and until the
given condition remains false.
Syntax: -
Do
Statement
----------------
----------------
------------
Increment/Decrement
Loop until (condition)
Exit Loop and Exit For Statement:
Exit Do and ―Exit For statement is used to terminate the loop on some condition
before satisfying the given condition.
The Exit Loop statement is used to terminate the DO – LOOP, DO WHILE – LOOP
.
And the Exit For statement is used to terminate the FOR – LOOP on some condition.
Syntax: -
Do while (condition)
------------------
------------------
If (condition)
Exit loop
End if
Loop
8. FOR EACH