<< Prev        Next >>

ID : 126

Do...Loop

Function

To repeatedly execute a set of statements while a designated condition is True or until the condition becomes True.

Syntax

Do [{While | Until} condition]
	'Statements
Loop

OR

Do
 'Statements
Loop [{While | Until} condition]

Guaranteed entry

While | Until
For "While," a set of statements is repeatedly executed while a designated condition is True. For "Until," a set of statements is repeatedly executed until a designated condition becomes True.
Condition
Designate by a conditional expression.

Description

[statements] are repeatedly executed until a condition becomes True or while the condition is True.

For "While," the processing is repeated while a designated condition is True and the system transits to lines after Loop when it becomes False.

For "Until," the processing is repeated while a designated condition is False and the system transits to lines after Loop when it becomes True.

The system goes into an infinite loop when {While | Until} condition is omitted.

It becomes a precondition when a condition is specified in Do, or postcondition in Loop.

Executing "Exit Do" in [statements] breaks the Do Loop processing.

If a command which processing time is short is repeatedly processed, other tasks operating as multi tasks are obstructed because the CPU is occupied by repeatedly processed command. To avoid that, insert "Delay" or "Wait" command between repetition processing. CPU is released from excessive task load while "Delay" or "Wait" command is processing, that improves efficiency of other tasks.

Related Terms

Exit, For...Next

 

Attention

-

Example

'!TITLE "Executing Testing Iteration"
' Repeatedly execute the processing until aaa becomes larger than 10
Sub Sample_DoLoop

  Dim aaa As Integer
  Dim bbb As Integer

  aaa = 1
  bbb = 0

  ' Addition of value between 1 and 10
  Do

    bbb = bbb + aaa
    aaa = aaa + 1

  ' Loop until aaa becomes larger than 10
  Loop Until aaa > 10

  ' Display "55" on the message output window
  PrintDbg bbb

End Sub

ID : 126

<< Prev        Next >>