manual:chapter5:basics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
manual:chapter5:basics [2021/09/15 10:24]
claudio
manual:chapter5:basics [2021/09/15 10:32] (current)
claudio
Line 423: Line 423:
   * ''A=11'' it will produce 11   * ''A=11'' it will produce 11
  
-Notice that despite the starting value being higher than the end value and the loop using ''NEXT'' (therefore it's a loop counting up), the loop executed at least once. This is because the decision to enter the loop is made when ''NEXT'' is reached.+Notice that despite the starting value being higher than the end value and the loop using ''NEXT'' (therefore it'a assumed to be a loop counting up), the loop executed at least once. This is because the decision to exit the loop is made when ''NEXT'' is reached.
  
 Now let's review a loop using ''STEP'' with a positive step: Now let's review a loop using ''STEP'' with a positive step:
Line 437: Line 437:
   * ''A=11'' it will produce 11,12,13,14,15,... infinite loop   * ''A=11'' it will produce 11,12,13,14,15,... infinite loop
  
-Notice that while the loop appears to count up by looking at the code, the condition A>10 causes the loop to be counting down because the start value is larger than the end value, and therefore it will only end when J<10, regardless of the magnitude and direction of the step.+Notice that while the loop appears to count up by looking at the code, the condition A>10 causes the loop to be counting down because the start value is larger than the end value, and therefore it will only end when J<10, regardless of the magnitude and direction of the step. Since the step increases the counter, the loop never ends.
  
-In situations where it is desirable to keep the direction of the loop fixedthe ''FORUP'' and ''FORDN'' commands can be used in lieu of ''FOR''. These two variants have two advantages:+In some situations it is desirable to keep the direction of the loop fixed regardless of the start/end values. The ''FORUP'' and ''FORDN'' commands can be used in lieu of ''FOR''. These two variants have two advantages:
   * The direction of the loop is fixed and known, regardless of the values the limits might have at run time.   * The direction of the loop is fixed and known, regardless of the values the limits might have at run time.
   * The loop has one additional check when the word ''FORUP'' or ''FORDN'' is executed. This allows for early exit without being forced to execute the loop clause.   * The loop has one additional check when the word ''FORUP'' or ''FORDN'' is executed. This allows for early exit without being forced to execute the loop clause.
  
-Back to the example used above for ''NEXT'' but in this case using FORUP to force the loop to count up:+Back to the example used above for ''NEXT'' but in this case using FORUP:
  
 <file> <file>
  • manual/chapter5/basics.txt
  • Last modified: 2021/09/15 10:32
  • by claudio