【问题标题】:nested loops - run day-by-day loop on 3 instruments嵌套循环 - 在 3 个仪器上运行日常循环
【发布时间】:2015-05-06 20:28:51
【问题描述】:

您好,我正在尝试对 200 天的数据运行一个循环,它应在 3 台仪器上一次读取 1 天。到目前为止,我可以在 3 台仪器停止之前运行一天(我使用“break”语句,否则它将运行一台仪器到最后)。

static public void downloade()
{
    string[] markets = { "CLK15", "HOK15", "GCJ15" };

    for (int i  = 0; i < markets.Length; i++)
    {

        string[] lines;
        WebClient client = new WebClient();
        string downloadString = client.DownloadString
                ("http://ds01.ddfplus.com/historical/queryeod.ashx?username=XX&password=XX&symbol=" + markets[i] + "&maxrecords=200&data=daily");
        lines = downloadString.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);


        for (int j = 0; j < closePrice.Length; j++)
        {
            Console.WriteLine(datePrice[j].ToShortDateString() + " " + closePrice[j]); 
            break;   
        }

        Console.ReadLine();
    }
}

【问题讨论】:

  • 您有具体的问题或问题?
  • 你在 closePrice 上的循环是没用的。您设置循环,然后在第一次迭代后立即中断。该循环只会在 j == 0 时执行,并且永远不会达到 j == 1。我不确定您的具体问题是什么?
  • 我需要在第 1 天到第 200 天(或 closePrice.length)运行一个循环,跨越 3 个工具。因此,对于第 1 天...获取工具 x、y、z 的价格...然后进行一些计算...完成后,我进入第 2 天并获取 x、y、z 的价格...。等等
  • 所以我的问题是......我该如何合并它?
  • 您的中断声明相当混乱。它打破了内部循环的迭代,因此您只能获得每个乐器的第一天。去掉这句话,一切都好。

标签: c# for-loop nested-loops


【解决方案1】:

我解决了这样的循环并删除了“break”语句。

for (int i  = 0; i < 100; i++)
                {
                    for (int j = 0; j < markets.Length; j++)
                    {

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多