This lesson will cover the use of a while loop. You will also learn how to add 1 and subtract 1 to a variable simply by placing either a ++ or -- respectively, after the variable name.

Code:
 
 
using System;
 

 
namespace WhileLoop
 
{
 
 ///<summary>
 
 /// Demonstration of While Loop
 
 ///</summary>
 
 class Class1
 
	 {
 
 ///<summary>
 
 /// Ask a series of math questions and score the individual
 
 ///</summary>
 
			 [STAThread]
 
 static void Main(string[] args)
 
			 {
 

 
 //if we don't initialize you will get an error 
 
 int answerOne = 0;
 
 double answerTwo = 0;
 

 

 
 int score = 0;
 

 
					 Console.WriteLine("A question will be asked.");
 
					 Console.WriteLine("It will be repeated if answered wrong.");
 
					 Console.WriteLine();
 

 

 
 while (answerOne != 2)
 
						 {
 
								 Console.Write("What is 4/2?: ");
 
								 answerOne = Convert.ToInt32(Console.ReadLine());
 

 

 
 if (answerOne != 2)
 
								 {
 
 //take away 1 from score if condition is met
 
 //that is, answerOne not equal to 2
 
										 score--;
 
								 }
 

 
						 }//end while loop for answerOne
 

 
 //add one to 'score' if the answer is correct
 
						 score++;
 

 
				 Console.WriteLine("Good job! Next Question:");
 
					 Console.WriteLine();
 

 

 
 while (answerTwo != .5)
 
						 {
 
								 Console.Write("What is 2/4: ");
 
 //We Convert.ToDouble since the answer is a real #
 
								 answerTwo = Convert.ToDouble(Console.ReadLine());
 

 

 
 if (answerTwo != .5)
 
								 {
 
										 score--;
 
								 }//end if statement
 

 
						  }//end while loop for answerTwo
 
						 score++;
 

 
					 Console.WriteLine("");
 
					 Console.WriteLine("You completed the quiz");
 
					 Console.WriteLine("Your Score is: {0}", score);
 
					 Console.ReadLine();
 

 

 

 
			 }
 
	 }
 
}
To add Qs and As you can simply add additional while loops with if statements.
The score-- and score++ is necessary to keep track of the score.

If you ever have a problem understanding the logic of a program or want to get a good grasp of how it works, (assuming you are using Visual Studio) you can press F11 and step through the program. At the bottom you will be able to see what the variable values are as you step through the program and the line(s) of code that are being stepped through will be highlighted in yellow as it is being executed. You can also toggle back and forth to your console and see what is going on there too.