Current location - Training Enrollment Network - Mathematics courses - Does the Do loop statement in Senior High School Mathematics Compulsory 3 judge the condition first or execute the loop body first?
Does the Do loop statement in Senior High School Mathematics Compulsory 3 judge the condition first or execute the loop body first?
There are two ways to control whether to execute a loop according to conditions:

1、Do[{ While | Until } & lt; Cycle condition >; ]

< ring body >

ring

In this form, the condition is first judged, and if the condition is met, the loop body is executed.

Example: Private Sub-Form _Click ()

Dim i is an integer and sum is an integer.

i= 1

Until I> 10

Sum = sum +i

i=i+ 1

ring

Print "1+2+...+ 10="; total

End joint

Step 2: do it

< ring body >

Loop [{while | until} < Cycle condition >; ]

In this form, the loop body is executed first, and it is judged whether the conditions are met after each execution (that is, the loop body is executed at least once).

Example: Private Sub-Form _Click ()

Dim i is an integer and sum is an integer.

i= 1

do

Sum = sum +i

i=i+ 1

Loop until i> 10.

Print "1+2+...+ 10="; total

End joint