Visual F#
Previous article describes is for ...... to ...... grammar, today re-introduced for ...... downto ...... grammar Hello!
★ syntax:
1: for ... downto ... Counting cycle - Syntax
2: for <variable> = <First count (open) the start value> downto <count final value> do
3: <main loop execution recited>
★ Demo:
1: // Nobel Hsieh ( http://www.dotblogs.com.tw/nobel12 )
2: open System;;
3:
4: // for ... downto ... Counting cycle - Syntax
. 5: // for <variable> = <First count (open) the start value> downto <count final value> do
6: // <recited cyclic execution body>
7:
8: let CountAddResult (initNum, finalNum) =
9: let mutable tmpTotal = 0;
10: // compared to the previous one case, the only change to the bottom of downto
11: for tmpI = initNum downto finalNum do
12: tmpTotal <- tmpTotal - tmpI;
13: printfn "After the last subtraction value:% d" tmpTotal ;;
14:
15: CountAddResult(100,97);;
16: System.Console.WriteLine("*");;
17: CountAddResult(2500,2498);;
18:
19: System.Console.ReadLine();;
* 11 cycles from the first line to the line 12, are counted for the body.
* Used for ... downto .. is tired reduction of the mean
★ The results showed that:
* In this case, deliberate manner to render the use of subtraction, so, it can make you feel downto the fu!
Original: Large column [F #, Basic] easy learning series (20) ─ the design cycle count cycle (b)