Doubt with these ST coding...

hcchin
2009-07-12
2009-08-03
  • hcchin - 2009-07-12

    Both Example has the 'Exit' operator, but it work differently... why...???

    I feel a bit strange at the 'Exit' operator in the Example 2..

    My understanding, In the example 1 and 2, the m3 For loop shouldn't be working with their condition because of the 'Exit' operator will end the innermost loop but the Example 2 works why?

    Anyone could help to explain...???

    For the Example 1,

    The IF condition's M200 always True and as a result

    M3 got 0 value.(it didn't loop at all).

    For The Example 2,

    The IF condition's when M1=M3 and as a result

    M3 got 5.

    IMG: For loop with Exit Operator_Q2.JPG

    IMG: For loop with Exit Operator_Q1.JPG

    for_test_with_exit2_ok.pro [23.66 KiB]

     
  • Igor Petrov - 2009-07-13

    You did 'Single cycle' in the debugger, therefore you saw only the final results – after the last iteration.

    In details:

    Inside 1-st iteration m1 = m3 = 0 – EXIT

    …

    Inside 6-st iteration m1=5, m3 = 0 – m3 runs from 0 to 5

    Do try to use a breakpoint and you will catch it.

     
  • shooter - 2009-08-03

    and please do not exit inside a loop as the stack will not be correct.

    do the question before the loop or after it.

     

Log in to post a comment.