//******************************************************************************//
//                              Do While Loop                                   //
//                              RobotC on NXT                                   //
//                                                                              //
//  This program allows your taskbot to run in a square five times.             //
//                                                                              //
//******************************************************************************//
//				Focus                                           //
//                                                                              //
//  This program allows your robot to move in a sqaure by repeating a forward   //
//  and right turn movement.  It will repeat this movement 20 times so your     //
//  robot does five squares. It tracks the number of times its completed the    //
//  movement with the variable "i".  "i" starts at zero and each time the loop  //
//  is competed 1 is added to "i"'s value.  So after one forward and right turn //
//  movement, "i" is equal to 1.  After 6 movements "i" is equal to 6 and after //
//  20 movements "i" is equal to 20. The repetition of the movement is          //
//  controlled by the loop command which ends itself when "i" equals 20.        //
//                                                                              //
//******************************************************************************//
//				Notes                                           //
//				                                                //
//  1. The wait times used may need to be customized depending on robot         //
//     configuration. Test your robot several times to find the best wait time  //
//     to get a 90 degree turn.  Once you have the proper timing, substitute it //
//     for the "wait1Msec(750)" command in the following program.               //
//  2. The robot will end facing the same direction as when it started.	        //
//                                                                              //
//******************************************************************************//
//				Motors & Sensors                                //
//                                                                              //
//  [I/O Port]          [Name]          [Type]          [Description]           //
//  Port A              none            Motor           Right Motor             //
//  Port B              none            Motor           Left Motor              //
//                                                                              //
//******************************************************************************//


task main()
{
   int i = 0;                //the variable "i" is declared as an integer, and initialized to equal 0

   do                        //do instructs the computer to run the code in its braces and after 1 iteration check the condition at the while statment that follows
   {
      motor[motorA] = 75;    //motor A is run at a 75 power level
      motor[motorB] = 75;    //motor B is run at a 75 power level
      wait1Msec(4000);	     //the program waits 4000 milliseconds before running further code

      motor[motorA] = 75;    //motor A is run at a 75 power level
      motor[motorB] = -75;   //motor B is run at a -75 power level
      wait1Msec(750);        //the program waits 750 milliseconds before running further code

      i++;                   //the variable "i" is incremented by one
   }
   while(i < 20);             //after each iteration of the loop is conducted, the truth condition, "i" less than 20, is checked

}                            //a closed brace signifies the end of task main's code