質問

I am stuck with a problem for exiting out of a while loop I have tried using break, Exit do

The algorithm for automated testcase goes as follows

while true
do some tasks
    if total >200 then 
       do some tasks 
       and 
       exit out of while loop if this condition reaches
    End if
wend
役に立ちましたか?

解決

If the only exit point is on the total > 200

do
    do_some_tasks
    if total > 200 then
        do_total_related_tasks
    end if 
loop until total > 200

that can be simplified to

do
    do_some_tasks
loop until total > 200
do_total_related_tasks

For a more general, multiple exit point, the fastest option is the exit do

do
    do_some_tasks
    if total > 200 then
        do_total_related_tasks
        exit do
    end if 
    other_tasks
loop while true

Or, for a more general solution, use a variable

keepTesting = true
do
    do_some_always_tasks
    ' start to test conditions
    if keepTesting then if total > 200 then 
        do_total_related_tasks
        keepTesting = false
    end if 
    if keepTesting then if other_exit_condition then
        .....
        keepTesting = false
    end if 
    .....
loop while keepTesting

Or whatever other construction depending of the real problem.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top