SQL SERVER – Simple Example of WHILE Loop With CONTINUE and BREAK Keywords

1) Example of WHILE Loop
DECLARE @intFlag INT
SET 
@intFlag 1
WHILE (@intFlag <=5)
BEGIN
PRINT 
@intFlag
SET @intFlag @intFlag 1
END
GO

ResultSet:
1
2
3
4
5

2) Example of WHILE Loop with BREAK keyword
DECLARE @intFlag INT
SET 
@intFlag 1
WHILE (@intFlag <=5)
BEGIN
PRINT 
@intFlag
SET @intFlag @intFlag 1
IF @intFlag 4
BREAK;
END
GO

ResultSet:
1
2
3

3) Example of WHILE Loop with CONTINUE and BREAK keywords
DECLARE @intFlag INT
SET 
@intFlag 1
WHILE (@intFlag <=5)
BEGIN
PRINT 
@intFlag
SET @intFlag @intFlag 1
CONTINUE;
IF @intFlag -- This will never executed
BREAK;
END
GO

ResultSet:
1
2
3
4
5

http://blog.sqlauthority.com/2007/10/24/sql-server-simple-example-of-while-loop-with-continue-and-break-keywords/

Understanding Recursion in C#

C# program that uses recursive method

using System;

class Program
{
    static int Recursive(int value, ref int count)
    {
	count++;
	if (value >= 10)
	{
	    // throw new Exception("End");
	    return value;
	}
	return Recursive(value + 1, ref count);
    }

    static void Main()
    {
	//
	// Call recursive method with two parameters.
	//
	int count = 0;
	int total = Recursive(5, ref count);
	//
	// Write the result from the method calls and also the call count.
	//
	Console.WriteLine(total);
	Console.WriteLine(count);
    }
}

Output

10              Total value of 10 was added up.
6               Six method calls.
http://www.dotnetperls.com/recursion