for loop = weird

This is a discussion on for loop = weird within the C# Programming forums, part of the General Programming Boards category; Ok, has anyone ever tried for loops in C#? test out this code: Code: using System; class MyClass { public ...

  1. #1
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230

    for loop = weird

    Ok, has anyone ever tried for loops in C#? test out this code:

    Code:
    using System;
    
    class MyClass
    {
           public static void Main(String[] args)
           {
                  int x;
                  for(x=0;x<10;x++)
                        System.Write(x);
            }
    }
    if you notice, the output is 123456789

    not exactly like C/C++/Java...hmmm, it'll be hard to remember to always make the number one higher than you want it to go to.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    As I notice, your code does not print anything, it doesn't even compile.

    This

    Code:
    using System;
    
    class MyClass
    {
    	public static void Main(String[] args)
    	{
    		int x;
    		for(x=0;x<10;x++)
    			System.Console.Write(x);
    	}
    }
    however produces "0123456789" as you would expect it.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    *note to self: I'm a moron*

    Sorry, I was trying to write it off the top of my head...

    and I did this yesterday on my upstairs computer, and it however read "123456789", I swear! but now it doesn't...damnit, I'm senile. Oh well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird things with my linked list of queue
    By -EquinoX- in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 10:23 PM
  2. weird
    By kiz in forum C Programming
    Replies: 8
    Last Post: 09-24-2007, 01:16 AM
  3. Weird Characters With GetDlgItemText
    By execute in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2006, 04:53 PM
  4. weird error
    By gandalf_bar in forum Linux Programming
    Replies: 2
    Last Post: 07-17-2005, 07:32 AM
  5. Getting weird characters in Strings
    By steve8820 in forum C Programming
    Replies: 3
    Last Post: 09-18-2001, 02:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21