Tuesday, March 5, 2013
Story Vomiting and Other Infinite Loops

Fact: I am 10 years older than my sister.

Fact: my sister was a prolific story vomiter when she was a toddler.

Maybe she would hear us talking about our favorite toothpaste, or maybe about what Ms. You-Know-You-shouldn’t-have-worn-than-hoochie-skirt-to-church Ma’am on Sunday evening.

All it would take is one spark and then she was gone.

She would tell the longest, run-on ever…and it was in the guise of a story. Literally, she would be blabbing rainbow and cookies for hours. Once she heard you come around the corner, “Hey, can I tell you a story?”

She would even prey on my parent’s guests. They would walk into the living room like stupid deer, in awe by the headlights of the cutest big cheeked girl you’ve ever seen in a while.

That’s when she’d throw her story coated rainbow at them. And, don’t think you could escape by going to the bathroom. She’d talk to the door.

She’d talk to the wall holding the door. I know this seems ridiculous. But, she literally would sit and talk to the wall for up to an hour. Just chilling.

Just to stick it to the man, she’d talk to your shadow. You’re done. You’re dying a slow and ear numbing death.

Once she started, she was on an infinite word spitting loop.

If I were to program my sister using PHP, I’d have two popular loopy choices: while or for.

## A note about loops, first.

Loops are essentially machines’ way of counting from one value to another. While they are counting, they may perform an action based on the current value. For example, the computer counts from 1 to 10 and at 5 it echos “Half way there!”.

Loops combine all of the previous lessons into one cute and cuddly gift box. To create a loop you need variables, expressions, and (possibly) a conditional statement, or six.

Loops require three things to operate:

A counter variable

A conditional statement for stopping the loop

A statement used to increment the variable

Note: If a loop is missing the conditional statement, or the incrementing statement, it becomes an infinite loop. Infinite loops can crash websites, stall your computer, and aggravate your nerves. Be careful. Loops are dangerous.

You have been warned.

## While Loops

While loops have the following syntax

`<?php While(ending condition if false){ Do something awesome Increment the counter } ?>`

For example
`<?php \$count = 0; while(\$count<11){ if(\$count == 5) echo "Halfway there!"; else echo “Counting….”; \$count++; } ?>`

## For Loops

For loops are while loops on crack. They cram everything in the beginning of the loop, like this:

`<?php for(create a counter variable; ending condition is false; increment the counter){ Do awesome things } ?>`

For example, let’s create the exact same loop from above, but with a for loop

`<?php for(\$count=0; \$count<11; count++){ if(\$count == 5) echo "Halfway there!"; else echo “Counting….”; } ?>`

Good luck! And don’t really program an infinite loop. Your computer might vomit on itself.

## This post has 4 Responses

• Nan says:

ha ha ha. I’m truly a story vomiter. But I always interrupt myself when I get distract . . . oh, look! There goes a butterfly!

• I usually already had half the conversation in my head before I started telling the story, lol. People get really confused, and I have no clue what exactly I forgot to say… because I thought I told it from the beginning.

Gah, I’ve become my mother!
Tiffany Barry recently posted…Guest Checkout Now Available