using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ForNextSample
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {            
            int total = 0;

            //count变量声明在for循环中，循环执行完成后就会被清除
            for (int count = 1; count <= 10; count++)
            {
                total += count;
            }
            //MessageBox.Show("Count = " + count);  //这一行会有编译错误
            lblResult.Content = total.ToString();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {    
            int total = 0;

            //count变量声明在for循环外，循环执行完成后仍可以使用
            int count;  
            for (count = 1; count <= 10; count++)
            {
                total += count;
            }
            MessageBox.Show("Count = " + count);
            lblResult.Content = total.ToString();
        }
    }
}
