Results 1 to 9 of 9

Thread: quick code

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    quick code

    ok this sounds easy but which is the best way of doing this?

    in a for loop (lets say up to 100), for numbers where a multiple of X, print something. for a multiple of Y print something else. For a multiple of X and Y, print something else.

    does that make sense? how would you find out (or the best way) if you are in multples?
    would that be the mod operator? if so, then would this be right?

    for (int counter = 0; counter < 100; counter++)
    {
    if (counter % X == 0)
    {
    Console.WriteLine("something 1");
    }
    else if (counter % Y == 0)
    {
    Console.WriteLine("something 2");
    }
    else
    {
    Console.WriteLine(counter.ToString());
    }
    }

    but what about the last part "if they are multples of X and Y"?
    Last edited by Techno; Jul 24th, 2007 at 10:41 AM.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width