-
Notifications
You must be signed in to change notification settings - Fork 89
While Loops
CodingUnit edited this page Nov 30, 2011
·
2 revisions
-
Category: For and While Loops
-
Description: A simple ’while’ loops that busy-waits until the given time-span has passed
-
Code:
using System;
using System.Console;
using System.Diagnostics;
def SampleWhileLoop2()
{
def timer = Stopwatch();
def duration = 8;
mutable count = 0;
WriteLine("Waiting...");
timer.Start();
// Here's the loop
while (timer.ElapsedMilliseconds < duration)
{
Write(".");
count++;
}
timer.Stop();
// OK, we're done...
def span = timer.ElapsedMilliseconds;
WriteLine($"\nAttempted to busy-wait 8ms, actually waited '$span'");
WriteLine($"Cycle counts for this time '$count' times.");
}
SampleWhileLoop2()
- Execution Result:
Waiting...
.........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Attempted to busy-wait 8ms, actually waited 8
[Copyright ©](Terms of use, legal notice)