While Loops - vilinski/nemerle GitHub Wiki

While Loops

  • 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)