Forum Migration Notice
Update (2026-01-21): The user forums are now in read-only mode pending the data migration.

Update (2026-01-12): The user forums will be put into read-only mode on the 21st of January, 00:00 CET, to prepare for the data migration.

We're transitioning to a more modern community platform by beginning of next 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.