09 December 2011

C# Lesson 9 : For Iterations

Iterations allow our applications to loop through a block of code until a condition is satisfied. We cover several different types of iteration statements throughout this series, how to utilize "code snippets" to help remind you of the syntax for this complex statement, and debugging in action.

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ForIterations
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                //Console.WriteLine(i.ToString());

              
                if (i == 7)
                {
                    Console.WriteLine("Found seven!");
                    break;
                }

            }

            for (int myValue = 0; myValue < 12; myValue++)
            {
                Console.WriteLine(myValue);
            }


            Console.ReadLine();
        }
    }
}
Source : MS Virtual Academy

No comments: