Skip to content

Instantly share code, notes, and snippets.

@manfre
Forked from Pharylon/gist:4502183
Last active December 10, 2015 22:28
Show Gist options
  • Save manfre/4502333 to your computer and use it in GitHub Desktop.
Save manfre/4502333 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
// This loop would be better broken out as a method that accepts
// start, end, and step values to control the loop. That would also
// require extra bounds checks for end < start, etc.
for (int i = 1; i <= 100; i++)
{
// Your check methods could be rewritten using modulos
bool fizz = i % 3 == 0;
bool buzz = i % 5 == 0;
// Print the Fizz Buzz parts without trailing newline
if (fizz)
Console.Write("Fizz");
if (buzz)
Console.Write("Buzz");
// Now add the newline
if (fizz || buzz)
Console.WriteLine("");
else
Console.WriteLine(i);
}
// You can press Ctrl+F5 to run your program and keep the window
// open when execution finishes. Or you can require a key press
//Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("Whoops!");
Console.WriteLine(ex.Message);
}
}
}
}
@Pharylon
Copy link

Thanks! I appreciate the feedback. That's a lot better of a solution than mine. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment