sketcher
9-25-02, 11:50 AM
Here is a programming question. I hope someone out there can answer it for me. I'm working in flash (Actionscript) but what I need to do is pretty much universal in all programming languages (I assume).
It's the age old for statement:
for (i=1; i<7; i++)
What I need is i can become any number from 1 to 7 but not 5. Is there a way to show this in a for statement?
Actionscript is derived from javascript which is derived from java (kinda) which is derived from C. So if it works in any of those languages, it should work in actionscript.
:glare: Huh?
:ego: <----Me trying to figure out what you just said.
I'll have the Bakliva (because its ALL GREEK TO ME!)
Roemello
9-25-02, 03:19 PM
Code scares me...:lol: Even the stuff I know like html, php and SQL...**makes hexing sign** :vibrator::lol::p
Shortie Blonde
9-25-02, 03:30 PM
It's soo easy! :lol:
This is gonna be harsh. :lol:
theghg=thghhghdsggkereafdlsfdlfgjkdgjit=1:lol: j/k
there have gotta be some people here who can really help you.
I've done a bit of C++ and I'm not sure if this is legal syntax or not, but is it possible to have (i=1; i<7 & i<>5; i++) It seems that there would have to be a <>5 in there somewhere. Perhaps (i=1; i<7; i<>5; i++)
sketcher
9-25-02, 03:56 PM
I don't know if that would work, Recker, but it's worth a try! :) thanks
Originally posted by sketcher
for (i=1; i<7; i++)
What I need is i can become any number from 1 to 7 but not 5. Is there a way to show this in a for statement?
Actionscript is derived from javascript which is derived from java (kinda) which is derived from C. So if it works in any of those languages, it should work in actionscript. [/B]
The answer depends on how you want the i integer to be generated. Can it be done randomly? If so, this should work:
#include <stdio.h>
#include <time.h>
int i;
randomize();
do {
i = rand(8); // always does number - 1
} while(i != 0 && i != 5);
for(i; i < 7; i++)
This is C code so the randomize might not work under actionscript. I know it works under Borland Turbo C++ because I used to use it all the time. Those header files probably won't apply to you, but I added them anyway.
There should be some sort of randomize command. You usually will need to start the random number generation, hence the call to the randomize() function.
Now if the integer is hard coded and not generated on the fly, you can do it another way. Let's say for example that i = 3. So we will make i = 3, but 5 must be skipped... cannot exist.
int i;
for(i=3; i<7 && i != 5; i++) {
// code here
}
That SHOULD work. I have never needed to do a statement quite like that, but I'm almost positive it will work. I don't feel like shelling to DOS and keying it into my compiler.
If it doesn't work, let me know and I can find another method.
An if then else ladder might work better. Just depends on what you need to do, and if optimization is necessary.
BTW, java is based more on C++. If you get the chance, you might look over C++. It has some cool features to it. I'm WAY better in C than C++ though.
Originally posted by Recker
I've done a bit of C++ and I'm not sure if this is legal syntax or not, but is it possible to have (i=1; i<7 & i<>5; i++) It seems that there would have to be a <>5 in there somewhere. Perhaps (i=1; i<7; i<>5; i++)
I believe the <> is illegal in C/C++. Seems like I tried it once and my compiler bitched about it.
The easiest method would be: i<7 && i != 5
Simply test the integer and make sure its less than 7 and NOT equal to 5. :)
Originally posted by Roemello
Code scares me...:lol: Even the stuff I know like html, php and SQL...**makes hexing sign** :vibrator::lol::p
I used to love to see statements something like this:
while (*ptr) != NULL {
database->element[x] = *addr * int_x / 2;
int++;
memcpy(new_array, old_array, sizeof(database->element);
}
Easy to read, a bitch to follow.
It's a wonder why so many programmers drink. :)