AhnafAbdullah27

Conditionals 3

Sep 11th, 2018 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Conditionals3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //While Loop
  14.             int number = 0;   // integer number is declared, set to 0
  15.  
  16.             Console.WriteLine("Enter an integer value.");   // asks for input
  17.             int IncrementOn = int.Parse(Console.ReadLine());   // integer IncrementOn is declared, set to the input of user
  18.  
  19.             decimal TickBegin = Environment.TickCount;  // declare number of milliseconds at that time, before starting increment
  20.             while (number < IncrementOn)  // increment code, loop is activated WHILE number < IncrementOn
  21.             {
  22.                 Console.WriteLine(number);  // writes the number
  23.                 number = number + 1;        // adds one to number, i find this more intuitive than ++number;
  24.             }
  25.  
  26.             decimal TickEnd = Environment.TickCount;    // declare number of milliseconds after counting,
  27.             decimal TimeTaken = (TickEnd - TickBegin) / 1000;    // Time taken = end time - start time
  28.             Console.WriteLine("Continuous incrementation took " + TimeTaken + " seconds. Press Enter.");  // notifying results
  29.             Console.ReadLine();  // pause
  30.  
  31.             //do Loop
  32.             number = 0;   // reset number to 0, since number is stuck at IncrementOn - 1
  33.             TickBegin = Environment.TickCount;  // reset timer
  34.             do   //increment code. loop is activated... wait... why is the condition below ._.
  35.             {
  36.                 Console.WriteLine(number);   // same as before
  37.                 number = number + 1;
  38.             } while (number < IncrementOn);  // conditions are below because this means the code will execute at least once
  39.             TickEnd = Environment.TickCount;  // reset timer
  40.             TimeTaken = (TickEnd - TickBegin) / 1000;  // new calculations
  41.             Console.WriteLine("Continuous incrementation took " + TimeTaken + " seconds. Press Enter.");  // notifying results
  42.             Console.ReadLine();   // pause
  43.  
  44.             //for Loop
  45.             number = 0;  // reset number to 0 again
  46.  
  47.             TickBegin = Environment.TickCount; // reset timer again
  48.             for (int i = 0; i < IncrementOn; i = i + 1)  // increment code, it's compact, but verryyyy complicated :/
  49.                 Console.WriteLine(i);           // same as before, for some reason, we declared a new variable, and put it in the for loop instead of here
  50.  
  51.             TickEnd = Environment.TickCount;   // mew calc
  52.             TimeTaken = (TickEnd - TickBegin) / 1000;     // new calc
  53.             Console.WriteLine("Continuous incrementation took " + TimeTaken + " seconds. Press Enter."); // results
  54.             Console.ReadLine(); // game over
  55.         }
  56.     }
  57. }
Add Comment
Please, Sign In to add comment