Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Conditionals3
- {
- class Program
- {
- static void Main(string[] args)
- {
- //While Loop
- int number = 0; // integer number is declared, set to 0
- Console.WriteLine("Enter an integer value."); // asks for input
- int IncrementOn = int.Parse(Console.ReadLine()); // integer IncrementOn is declared, set to the input of user
- decimal TickBegin = Environment.TickCount; // declare number of milliseconds at that time, before starting increment
- while (number < IncrementOn) // increment code, loop is activated WHILE number < IncrementOn
- {
- Console.WriteLine(number); // writes the number
- number = number + 1; // adds one to number, i find this more intuitive than ++number;
- }
- decimal TickEnd = Environment.TickCount; // declare number of milliseconds after counting,
- decimal TimeTaken = (TickEnd - TickBegin) / 1000; // Time taken = end time - start time
- Console.WriteLine("Continuous incrementation took " + TimeTaken + " seconds. Press Enter."); // notifying results
- Console.ReadLine(); // pause
- //do Loop
- number = 0; // reset number to 0, since number is stuck at IncrementOn - 1
- TickBegin = Environment.TickCount; // reset timer
- do //increment code. loop is activated... wait... why is the condition below ._.
- {
- Console.WriteLine(number); // same as before
- number = number + 1;
- } while (number < IncrementOn); // conditions are below because this means the code will execute at least once
- TickEnd = Environment.TickCount; // reset timer
- TimeTaken = (TickEnd - TickBegin) / 1000; // new calculations
- Console.WriteLine("Continuous incrementation took " + TimeTaken + " seconds. Press Enter."); // notifying results
- Console.ReadLine(); // pause
- //for Loop
- number = 0; // reset number to 0 again
- TickBegin = Environment.TickCount; // reset timer again
- for (int i = 0; i < IncrementOn; i = i + 1) // increment code, it's compact, but verryyyy complicated :/
- Console.WriteLine(i); // same as before, for some reason, we declared a new variable, and put it in the for loop instead of here
- TickEnd = Environment.TickCount; // mew calc
- TimeTaken = (TickEnd - TickBegin) / 1000; // new calc
- Console.WriteLine("Continuous incrementation took " + TimeTaken + " seconds. Press Enter."); // results
- Console.ReadLine(); // game over
- }
- }
- }
Add Comment
Please, Sign In to add comment