Monday, February 09, 2015

Getting back into some coding; LOOPS

Started small today to jump back into programming. I started off with some simple loops lik

(Oh also i'm going back C#)

using System

class Forever
{
        public static void Main ()
       {
             do
             Console.WriteLine ("Heya");
             while ( true );
        }
}

Is an infinite loop that will keep going while the word Heya is true. While it's continously true the loop will keep producing the line of text Heya infinitely


Then there is the while loop

using System

class While
{
              public static void Main ()
              {
                      int i;
                      i = 1;
                      while ( i < 11)
                       {
Console.WriteLine("Yo");
i = i + 1;
                       }
              }
}


In the while loop you set up the variables and give the variable or the control variable (i) a starting point. Then as the while loop progresses it adds +1 to the counter. 1 becomes 2 and increments with each passing.

This always got me though. The for loop always seemed to confuse me as it was so nested and i really couldn't make heads or tails of it but i finally got it down...

using System

class forLoop
{
public static void Main()
{
int i;
for (i = 1; i < 11; i = i +1)
{
Console.WriteLine("Sup");
}
}
}


that 3 part right there was what confused me. But it's basically the setup, when to end, how to get to the ending.


Also i really need to think of the reverse of a problem instead of gunning towards it. I have noticed a lot of my programs i did in high school involved how to NOT accept the bad values and accept the ones we want to be validated.

i won't be loading this into github as it's really not worth uploading some loops. I'll wait for a bigger program for it.