• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Testing code problem

Status
Not open for further replies.

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,219
hi, in my new school we got programming lessons and since I know basic jass the stuff they said on the first lessons I allready knew more or less. Like variables etc.

However we are supposed to learn C# and I got the "microsoft visual C# express " program to code in. However I dont get how to test my code. I just made simple test.

JASS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("afafkaf");
            Console.WriteLine("sdsa");
        }
    }
}


nothing happens when I try to test this, the cmd windows pops up for 0.1 seconds and then nothing. I get no errors from the program saying syntax error etc
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
hi, in my new school we got programming lessons and since I know basic jass the stuff they said on the first lessons I allready knew more or less. Like variables etc.

However we are supposed to learn C# and I got the "microsoft visual C# express " program to code in. However I dont get how to test my code. I just made simple test.

JASS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("afafkaf");
            Console.WriteLine("sdsa");
        }
    }
}


nothing happens when I try to test this, the cmd windows pops up for 0.1 seconds and then nothing. I get no errors from the program saying syntax error etc

Make your window either wait some time or for user response. It kind of makes sense that a program closes once it finishes doing stuff.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Yes except the command window is closed when the program finishes execution which happens virtually instantly. You need to either run it from a command window (which will not close after execution) or you need to keep the main thread alive (get it to sleep forever). Additionally some IDEs will log all output somewhere, even if the program finishes execution. You could also run the program in debug mode with a break point just before the main thread ends.
 
It will throw error in C# as well.

Anyway take this example
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                Console.Write(i + "\n"); 
            }
            Console.Write("\n"); 
            for (int i = 0, j = 9; i < 10; i++, j--)
            {
                Console.Write(i + " : " + j + "\n");
            }
            Console.Write("\n"); 
            for (int i = 0, j = 9; i < 10; )
            {
                    i++; 
                    j--;
                    Console.Write(i + " : " + j + "\n"); 
            }

            Console.Read();
        }
    }
}

For 1 ->
0
1
2
3
4
5
6
7
8
9

For 2 ->
0 9
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
9 0

For 3 ->
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
9 0
10 -1

Because in this 3rd case we first increase/reduce i/j and then write it, while in first 2 we do this after whole checking, you can use this analogy with while and do while loops.
 
Status
Not open for further replies.
Top