문제

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