Suppose i have this code

suppose i have this code.

is there a way to use a variable in a for loop that already has a value assigned to it?

i don't necessarily want to assign a new variable with the same value to work with that value.

>>>sqt

let's see.

>SQT
>Seal Qualification Training (US Navy)
>System Quality Testing
>Structured Query Translation
>Specialized Qualification Training
>Ship's Qualification Trial/Test
>Stable Queue Transaction Manager (Sybase)
>Supplementary Qualifying Test (UK)
>State Qualifying Tournament
>Systems Qualification Test(s)
>Skill Qualification Test
>Software Qualification Test
>Software Quality Test
>Streaming Quote Trader (securities exchange)
>Superquantum Theorie
>Ship Qualification Trials
>Schools Question Time

ok

lrn2scope and

I'll just say yes and leave you to work it out for yourself.

What a newbie code

assholes. what the fuck does this have to do with scopes? i'm trying to use a variable that has already been initialized.

and i found the solution.

...
int x = 9001;
for (x = x; x < 10001; x++) ...

really weird design, but works.

any tips?

you seem to have familiarized with that board :^)

jesus if your code looks like that just quit cs and take geology or something, fucking horrible, just say what you are trying to achieve and someone will write an algorithm, dont make us trouble-shoot your fucking spaghetti

>int x = 9001;
>for (x = x; x < 10001; x++) ...
Why not just
for (x; x < 10001; x++)
?

this is literally what i have in OP, bro do u even read, it doesn't work

It's because your 'x' variable isn't the same that your 'x' in the "for".

int x = 9001;
for (int x = x ; x < 10001 ; ++x)...
...
printf("%d", x);

>9001

>your code is horrible
everyone will say that to 99% of all existing code.
also i'm not making you trouble-shoot, wtf are you on about?

made a better version, but can't get rid of these for-loops. do you have a better idea?

What are you trying to do here? What's your goal.

There must be a better way than this shameful code you just wrote, OP.

this is not going to work because you declare x twice.

>...
>int x = 9001;
>for (x = x; x < 10001; x++) ...
>really weird design, but works.

>"but works"

So OP is a fucking fagget

Can you explain what you're actually trying to do??

Also, you should be assigning some initial value to k and l before you use them. Otherwise, they could contain trash

And when I say "What are you trying to do", I mean, explain the purpose of this program and what the inputs are.

IDEK what I'm really working with here

i have data in an array.
i move a window of size 1024 along this array.
the window jumps 128 indices further.
yes there is going to be redundant reading.
yes it is necessary.
i need 0-padding in the beginning scrolling into the data with said window.

>"but works"
I'm 100% sure it's a wintard

>you should be assigning some initial value to k and l before you use them
i do?
>k = 1024-128*i
>l = 0

i said "it works" because it's convenient for something that seems weird at first. i've just never seen or used a notation like x = x before.
i'm used to for-loops initializing their own variable.

Oh, sorry, didn't see the updated code. I was looking at the one up top, where only if(i == l)

that's if(i == 1), not if(i == l)
blame the font

so please now, do this :

for (int i = x ; ......)

"Window" as in 'range', I take it?

So, this thing must read 1024 cells every time, and it must adjust itself by 128 cells for each cycle?

oh.... ok, then

yes u can.
Wtf did you even try it?
Its 10 letters (including Compile key combination) vs three sentences and image copying.

you can do
for (; x < 1000; ++x)

why? i don't want an extra variable if i can use one that already has the value i need.

yes, correct. see pic

Ok, what special operations must happen at the beginning and end?

Does it wrap around, or does it use a default value, like 0?

nice! thank you, that is great

it does the same at the end, it will go beyond data point 4096 and pad with 0 again

stupid questions thread is what he means, but personally i dont think its a stupid question.

ok.

for(int i = 0; i < 4096; i += 128){
for(int j = 0; j < 1024; j++){
someArray[j] = ((j + i >= 4096) || (j + i < 0)) ? 0 : otherArray[(j + i)];
}
}


I haven't tested this, but I think it should work.

wait, I think I screwed up something.

Let me actually make a dummy program.

I'm tired atm.

Gimme about 5 mins

ye, j + i is never going to be < 0. the rest seems fine actually.
it looks good. but is it actually faster? it seems there is a lot of condition testing every iteration.

anyway, thanks a bunch for the effort actually. i didn't expect this.

Think I almost got it.

I got it reading in reverse order, by mistake atm, i think

what language are you actually using there btw, OP?
the code you posted should work fine in c, c++ and java

it will always be in O(N2), it is nice though to have two for-loops combined into one like your second one

oh? it's in c#

for(int i = 0; i < 4096; i += 128){
printf("\nNext Row: ");
for(int j = 0; j < 1024; j++){
//nums2[j] = ((j + i < 4096) && (i - j > 0)) ? 0 : ((i - j < 0) ? nums)
nums2[j] = ((j + i >= 4096) || (i - j < 0)) ? 0 : ((i - j > j + i) ? nums[i - j] : nums[j + i]);
printf("%d ", nums2[j]);
}
}


This is ALMOST complete. I'm just having a problem with the beginning and end.
It doesn't print the first 128 yet, and it seems to stop early.

Gimme a bit more time on this

>compsci graduate.png

i'm too tired as well by now, can barely follow the logic in the algorithm anymore :)

yeah, sorry. I've been up since ~4:30 PM. It's 8:30 AM, now.

I'm pretty sure it's some stupid shit I'm missing, though.

Here's the whole code I got so you can mess with it.
#include

int main()
{
int nums[4096];
int nums2[1024];

for(int i = 0; i < 4096; i++){
nums[i] = i;
}
for(int i = 0; i < 1024; i++){
nums2[i] = i;
}

for(int i = 0; i < 4096; i += 128){
printf("\nNext Row: ");
for(int j = 0; j < 1024; j++){
nums2[j] = ((j + i >= 4096) || (i - j < 0)) ? 0 : ((i - j >= j + i) ? nums[i - j] : nums[j + i]);
printf("%d ", nums2[j]);
}
}
return 0;
}

As you can see, though, the problem seems to be the placement of the array. It doesn't actually start before the 0, which I didn't actually notice until after I did it.

Hope you can figure it out when you also wake up.
This is gonna bother me, but I'm tired.

nice, bro, thank you so much!!
you really didn't have to do this.

i'll look into it tomorrow and see if i can optimize it a little. the condition testing each iteration will be of concern.

thanks again and good night! (it's 2:46 AM here)

K, have a good one.

Why not just

int i = 9000000
/*
*Code
*/
for(i; i < your_mom; i++)

What the fuck is even going on in this thread? The correct response is in the third (and first) post, why are you aspies helping the newshit OP who obviously hasn't spent even 10 minutes on this board? You're only encouraging more of this cancer

Have you tried
for(; x < limit; x++)

>it took all these posts for someone to get it right
neo Sup Forums