"Fossies" - the Fresh Open Source Software Archive

Member "dx-4.4.4/help/dxall270" (5 Feb 2002, 6293 Bytes) of package /linux/misc/old/dx-4.4.4.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!F-adobe-helvetica-medium-r-normal--18*
    2 #!N 
    3 #!CNavyBlue #!N  #!Rall269 Advanced Looping Constructs #!N #!EC #!N #!N 
    4 Combinations of the modules described above enable you to create advanced 
    5 looping constructs. These constructs are equivalent to C-language constructs such as 
    6 "do while" or "for" loops containing "break" and "continue" statements. In 
    7 the following figures the Sum and Increment macros, as described above, 
    8 are used as well as a macro named Equals that consists 
    9 of a Compute where the expression is "a==b?1:0" (if the inputs 
   10 are equal output 1 otherwise output 0). #!N #!N Illustrated in 
   11  #!Lxmodx844,dxall270 f Figure 44  #!EL  is a macro that computes the sum of numbers from 
   12 1 to N. If a number in the sequence from 1 
   13 to N is equal to an external input, x, the loop 
   14 terminates and returns the sum from 1 to x. Done, in 
   15 combination with Equals, is used to cause early termination of the 
   16 loop. Done causes the loop to terminate after all the modules 
   17 in the macro have executed if the input to Done is 
   18 nonzero. The macro illustrated in  #!Lxmodx844,dxall270 f Figure 44  #!EL  is equivalent to the C-language 
   19 statements: #!CForestGreen #!N #!N  #!F-adobe-courier-bold-r-normal--18*   #!N sum = 0; #!N i 
   20 = 0; #!N do #!N { #!N i++; #!N sum = 
   21 sum+i; #!N } while (i<=n && i!=x); #!EF #!N #!N #!EC 
   22 #!N #!N Now consider a macro in which the sum of 
   23 numbers from 1 to N is computed, but if a number 
   24 is equal to an external input value, x, it is excluded 
   25 from the sum. To achieve this result using C-language statements, you 
   26 would use a conditional with a "continue" statement: #!CForestGreen #!N #!N 
   27  #!F-adobe-courier-bold-r-normal--18*   #!N sum = 0; #!N for (i=1; i<=n; i++) #!N 
   28 { #!N if (i==x) continue; #!N sum = sum+i; #!N } 
   29 #!EF #!N #!N #!EC #!Cbrown #!N  #!F-adobe-times-medium-r-normal--18*    #!Rxmodx844 #!N Graphics omitted 
   30 from Online Documentation. Please see the manual. #!N #!N Figure 44. 
   31 Example 8 #!EF #!N #!EC As illustrated in  #!Lxmodx945,dxall270 f Figure 45  #!EL  , you 
   32 would use Route to create this macro using Data Explorer. The 
   33  #!F-adobe-times-bold-r-normal--18*   selector #!EF input of Route is being controlled by the 
   34 output of Compute. The Compute has its expression set to "a==b?0:1" 
   35 (if a and b are equal output 0, otherwise output 1). 
   36 (This is similar to the Equal macro used earlier, but the 
   37 expression differs slightly.) Therefore, if the iteration variable is equal to 
   38 x, Compute outputs a 0, causing Route to disable the execution 
   39 of all the modules downstream from it. This implies that Sum 
   40 and SetLocal will not run; therefore, during the next iteration, GetLocal 
   41 will retrieve the same value as the current iteration. #!N #!N 
   42 Unfortunately, the visual program illustrated in  #!Lxmodx945,dxall270 f Figure 45  #!EL  has a minor problem. 
   43 If x equals N, the Route will cause the Sum and 
   44 SetLocal not to execute during the last iteration; therefore the output 
   45 of the macro will be a NULL. #!Cbrown #!N  #!F-adobe-times-medium-r-normal--18*    #!Rxmodx945 
   46 #!N Graphics omitted from Online Documentation. Please see the manual. #!N 
   47 #!N Figure 45. Example 9 #!EF #!N #!EC Illustrated in  #!Lxmodx1046,dxall270 f Figure 46  #!EL  
   48 is the fix to the problem. A Switch is included to 
   49 choose the correct input for the output of the macro. If 
   50 x equals N, the output of the GetLocal is chosen; otherwise 
   51 the output of Sum is chosen. #!Cbrown #!N  #!F-adobe-times-medium-r-normal--18*    #!Rxmodx1046 #!N 
   52 Graphics omitted from Online Documentation. Please see the manual. #!N #!N 
   53 Figure 46. Example 10 #!EF #!N #!EC #!N #!N If you 
   54 want to create a loop containing an early exit in the 
   55 middle of the loop (a "break"), you need to use a 
   56 Route in combination with Done. Illustrated in  #!Lxmodx1147,dxall270 f Figure 47  #!EL  is a macro 
   57 that performs the equivalent function as the C-language statements: #!CForestGreen #!N 
   58 #!N  #!F-adobe-courier-bold-r-normal--18*   #!N sum = 0; #!N for (i=1; i<=n; i++) 
   59 #!N { #!N if (i==x) break; #!N sum = sum+i; #!N 
   60 } #!EF #!N #!N #!EC #!N #!N Data Explorer allows you 
   61 to have multiple Done tools in a single loop enabling you 
   62 to have more than one break or continue or combinations of 
   63 the two. #!Cbrown #!N  #!F-adobe-times-medium-r-normal--18*    #!Rxmodx1147 #!N #!N Graphics omitted from 
   64 Online Documentation. Please see the manual. #!N Figure 47. Example 11 
   65 #!EF #!N #!EC #!N #!N ForEachN or ForEachMember simplify the use 
   66 of loops but they are not necessary for creating them. In 
   67 fact, Done itself is sufficient, if it is included inside a 
   68 macro. The macro will execute repeatedly as long as the  #!F-adobe-times-bold-r-normal--18*   
   69 done #!EF parameter is equal to 0 (zero). Note that the 
   70 top-level visual program is itself a macro, so the same behavior 
   71 will occur if Done is placed in the top-level visual program. 
   72 #!N #!N Illustrated in  #!Lxmodx1248,dxall270 f Figure 48  #!EL  is a macro that computes the 
   73 Fibonacci Series (defined by setting Y[1]= 1, Y[2] = 1 and 
   74 by the recursion formula Y[k] = Y[k-2] + Y[k-1], for k 
   75 = 3,4,5...). In this example a two vector, [Y[k-1], Y[k]], is 
   76 used to store the elements of the series. The GetLocal module 
   77 has its initial value set to [1,1]. The first Compute in 
   78 the macro creates a new two vector consisting of [Y[k-1], Y[k]] 
   79 using the expression "[a.1, a.0 + a.1]." The second Compute in 
   80 the macro extracts Y[k] from the two vector using the expression 
   81 "a.1." To terminate the loop, the Y[k] element of the series 
   82 is checked against an external input, x. If Y[k] is greater 
   83 than x, the loop terminates. GreaterThan is a simple macro consisting 
   84 of a Compute with its expression set to "a>b?1:0." An equivalent 
   85 set of C-language statements is: #!CForestGreen #!N #!N  #!F-adobe-courier-bold-r-normal--18*   #!N a=1; 
   86 #!N b=1; #!N do { #!N c = b; #!N b 
   87 = b + a; #!N a = c; #!N } while 
   88 (b <= x); #!EF #!N #!N #!EC #!Cbrown #!N  #!F-adobe-times-medium-r-normal--18*    #!Rxmodx1248 
   89 #!N Graphics omitted from Online Documentation. Please see the manual. #!N 
   90 #!N Figure 48. Example 12 #!EF #!N #!EC #!N #!N #!N 
   91  #!F-adobe-times-medium-i-normal--18*   Next Topic #!EF #!N #!N  #!Lall270,dxall271 h External Asynchronous Data Sources  #!EL  #!N  #!F-adobe-times-medium-i-normal--18*   #!N