Programming for Assholes #1

By Anonymous Asshole

#1: Give up now...

I am sickend by your incompitance... You should just give up now. You will never be able to program, so just go home.

What? Are you still here? Okay, I'll show you, but I don't expect you to understand...

We are going to be working with FreeBASIC because I don't care what language you like. If you had half a brain, which you don't, you would be able to transition all this to other languages. Even non BASIC languages.

First is the idea of program flow. Programs, much like the tears of the many people disappointed with you, flow top to bottom in most cases. And as they move their tears with tissue, we move program flow with special programming structures. The simplist way is with loops, which I am sure you will have no idea what to do with.

There are many kinds of loops, but since you are more dense than a lead brick in a black hole, we will have to take them one at a time.

Automatic Counter Loop

This is a loop that counts from one number to another: a skill which you never mastered. In every language, you supply a start number, an end number, and how to increment. Some languages do the increment part for you or make it optional. That is probably best for you.

In FreeBASIC, this is done with the For...Next block.

For <variable> = <start> to <end> step <increment>
     'stuff to do here
Next <variable>

 

The variable is loaded with <start> then adds <increment> to it until it is larger than <end>. That means if end is 10, the loop won't stop until the variable is 11. By default, in FreeBASIC, if step is left out, increment is +1. This makes it easy for people who still have their brain in pawn.

You are probably asking: Why would I want to count from one number to another in code? I am assuming that is what you are trying to say, but all I am hearing is "DUH!"

You can use this for all sorts of things. It can be used to make sure that you only do something as many times as needed, or you can use the variable to position things on the screen, or even used to access a range or array positions. But to explain all that to you would take forever.

 

Do While

The Do While loop is a little different, so you should just pack your bags and give up. Instead of counting from one number until another, it loops as long as a condition is true.  In freeBASIC it looks like this:

While <condition>
     'Stuff to do here
Wend

The condition is checked at the top of the loop so if it is not true, the loop will not even run once.  So if it was checking "you = notATotalFailure", it would never have a chance of running.

This loop is awesome for reading from files.  Combine it with EOF(fineNumber) and it will make sure you don't read past the end of the file, even if it is as empty as your head.

Do Until

The Do Until loop insures that the loop runs at least once because the condition is checked at the end of the loop.  In freeBASIC it looks like this:

Do
     'Stuff to do here
Loop Until <condition>

This loop is good for games, or applications, or anything else that needs to run at least once, like your poor parents on the day of your birth.

Conclusion

Even though I have no hope that you can:  Experiment.  Send in your least horrible uses of the Automatic Counter, Do While, and Do Until loops and they may get featured in the next issue.

Until next time: You disgust me...

 

Powered by CMSimple | CMSimple Legal Notices | (X)html | css | Login | Template-Design: Lars Ellmauer | Template-Modified: Imortisoft ISD