This is a small C++ Program I made, It simply uses a batch command to make the background change colours epicly fast, so I called it 'Flash'.
I included the code with it just in case you people are scared o_o.
Yeah it's basic, I know.
I made this a while ago but just decided I'd post it.
using namespace std;
numbz = 0; //Integarz
for ( ; ; )
static const char *colourlist; //array with the colourz
colourlist = "color 0a";
colourlist = "color 1b";
colourlist = "color 2c";
colourlist = "color 3d";
colourlist = "color 4e";
colourlist = "color 5f";
colourlist = "color 6b";
colourlist = "color 7a";
colourlist = "color 8f";
colourlist = "color 9e";
numbz++; //Infinite loop of changing colours
if(numbz>9) //Each time it does teh loop numbz goes up and it plays teh specified Array thing
numbz=0;//reset it back to 0 once it's past 9 so it keeps changing :biggrin.gif:
I commented some stuff because I was boooored.
Rollback Post to RevisionRollBack
Celebrating the full version with the fan is going to be an amazing experience. I am a bit nervous about it, to be honest.
There's many differences, as you might notice, the biggest of which is that I moved the creation of the array outside of the loop and also initialized it. See, when you declare something, you can initialize it on the same line, and you should if you can. There's a small difference between initializing a variable as it's being created and declaring a variable and then putting values into it. The former is slightly faster than the latter, and it does matter if you'll be doing a lot of initialization.
Here, I've shown you the syntax for initializing an array and also for initializing a regular variable (numbz, which is done in the loop).
For loops are fun because you can get them to do things for you rather than placing that code elsewhere in your program. Here, I've got it creating the numbz variable and also incrementing it. The first statement executes once before the loop begins, the second is for the logic check to see if the loop should continue (it executes before each iteration, and the return value is used to determine whether the loop continues or not), the third is any statement you want to execute at the end of each iteration.
I also did the logic for resetting numbz back to 0 once it hits 9 a bit differently. For things like this, I prefer to use the modulo ( % ) operation. What it does is divides the value on the left by the value on the right and returns the remainder (9 % 4 = 1; 5 % 3 = 2). Here, I've used the unary version of that, so it performs the operation using the value of the variable on the left and the value of the entire right side of the equation and then sets the variable on the left to the return value. It's just a little bit more elegant.
Mostly, my code is just cleaner. All programmers should strive for nice, clean code, though.
You also have a one-off error in your loop logic. Your loop will bring numbz up to 10 and execute using that value, yet your array only goes from 0-9. You will not get a compiler error for attempting to access colourlist, and the program will happily do it, but you do not know what that data is. This is what's known as a buffer overflow, and it's dangerous behavior in a program.
Now, thankfully you're not actually running into anything and most CPUs and OSs have protection against this sort of thing, but that doesn't mean it still can't cause unintended behavior. Re-evaluate your loop logic and fix that error.