15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

OC174 ❘ ChaPTer 53 c#, visuAl bAsic, c++/cli, And f#<br />

for (int i = 0; i < 100; i++)<br />

{<br />

Console::WriteLine(i);<br />

}<br />

' Visual Basic<br />

Dim count as Integer<br />

For count = 0 To 99 Step 1<br />

Console.WriteLine(count)<br />

Next<br />

// F#<br />

for i = 1 to 10 do<br />

printfn i<br />

for i = 10 downto 1 do<br />

printfn i<br />

while <strong>and</strong> do . . . while statements<br />

The while <strong>and</strong> do…while statements are the same in <strong>C#</strong> <strong>and</strong> C++/CLI. Visual Basic has very similar<br />

constructs with Do While/Loop <strong>and</strong> Do/Loop While. F# doesn’t have a do/while but a while/do:<br />

// <strong>C#</strong><br />

int i = 0;<br />

while (i < 3)<br />

{<br />

Console.WriteLine(i++);<br />

}<br />

i = 0;<br />

do<br />

{<br />

Console.WriteLine(i++);<br />

} while (i < 3);<br />

// C++/CLI<br />

int i = 0;<br />

while (i < 3)<br />

{<br />

Console::WriteLine(i++);<br />

}<br />

i = 0;<br />

do<br />

{<br />

Console::WriteLine(i++);<br />

} while (i < 3);<br />

' Visual Basic<br />

Dim num as Integer = 0<br />

Do While (num < 3)<br />

Console.WriteLine(num)<br />

num += 1<br />

Loop<br />

num = 0<br />

Do<br />

Console.WriteLine(num)<br />

num += 1<br />

Loop While (num < 3)<br />

// F#<br />

let i = 0<br />

let mutable looping = true<br />

while looping do<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!