Forum Migration Notice
We're transitioning to a more modern community platform by the end of this year. Learn about the upcoming changes and what to expect.

While Loop

Hi' All

How to  exit  while loop and continue next command ?

Example    

    VAR num sum;
    PROC testwhile()
        WHILE TRUE DO
            Incr sum;
            IF sum = 10 THEN
                TPWrite "Sum :" \Num:= sum;
                ! ----------  Exit while loop and continue command
            ENDIF 
        ENDWHILE
    ENDPROC

PROC summ()
    testwhile;
   TPWrite "Exit loop while";
ENDPROC

Thanks for help.

Comments

  • Hello
    There is no break command but you could set a condition for the while loop like WHILE  NOT sum = 10 THEN
    /Pavel
  • Something like this

        VAR num sum;
        VAR bool bExit:=FALSE;

        PROC testwhile()
            WHILE NOT bExit DO
                Incr sum;
                IF sum = 10 THEN
                    TPWrite "Sum :" \Num:= sum;
                    bExit:=TRUE;
                    ! ----------  Exit while loop and continue command
                ENDIF 
            ENDWHILE
        ENDPROC

    PROC summ()
        testwhile;
       TPWrite "Exit loop while";
    ENDPROC
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Hi,All

    Thanks for help.