Loop for success


I was thinking about what it takes to follow through and achieve goals- I came to the conclusion that it's just all about writing good loops that keep you going- that keep you repeating the same behaviors/activities required to achieve your goal-

A simple C# "for" loop looks like this

for(int index = 0; index < listOfItems.Count; index++)
{
//do this
//then this
// then this etc
}

What this is doing is looking at your listOfItems and repeating the same thing over and over until it's gone through the whole list-

It will only STOP when the whole list is finished-

So let's say for example- this "list" is a shot list for an animation or film?

The loop will keep running until you have gone through the whole shot list- with this current code it won't stop for any other reason-

This part controls when it stops " index < listOfItems.Count "

index is being incremented each time with index++

So again, it will only stop when index is not less than the number of items-

Wouldn't it nice if you couldn't program yourself like this? So that you only stopped when all the work was done?

In reality if we were programmed these loops would have lots of "OR" operators which look like this ||

So if you write if( A == true || B == true) you're saying if A OR B is true- if we put this in our loop if would stop if A or B is true-

So this is how most people's loops would look like-

for(int index = 0; index < listOfItems.Count || decidesThisIsTooHard || fakeBookBeckonsTooMe || isReallyDrunk ; index++)
{
//do hard repetitive work
}

A more productive loop looks like this-

for(int index = 0; index < listOfItems.Count || iamPhysicallyDead ; index++)
{
// do hard repetitive work
}
So whatever it is you're trying to do-

Get it down to a repeating list of actions and loop through it with NO IF's - &&ND's - or ||OR's

I would say its ok to use XOR because sometimes you have to keep things secret-

Comments

  1. Great advice. I'm going to follow it //do what dot says

    ReplyDelete
  2. Using coding to give life advice. Brilliant.

    ReplyDelete

Post a Comment