[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

suppose i have this code. is there a way to use a variable in

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 52
Thread images: 6

File: why.jpg (26KB, 353x227px) Image search: [Google]
why.jpg
26KB, 353x227px
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
>>
>>58777055
>>58777055
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
>>
>>58777040
lrn2scope and >>>/g/sqt
>>
>>58777040
I'll just say yes and leave you to work it out for yourself.
>>
File: 1465540483703.gif (835KB, 480x270px) Image search: [Google]
1465540483703.gif
835KB, 480x270px
What a newbie code
>>
>>58777077
>>58777082
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.
>>
>>58777093
any tips?
>>
>>58777077
>>58777055
you seem to have familiarized with that board :^)
>>
>>58777040
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
>>
>>58777112
>int x = 9001;
>for (x = x; x < 10001; x++) ...
Why not just
for (x; x < 10001; x++)
?
>>
>>58777249
this is literally what i have in OP, bro do u even read, it doesn't work
>>
>>58777112
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
>>
File: better.jpg (27KB, 328x193px) Image search: [Google]
better.jpg
27KB, 328x193px
>>58777246
>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.
>>
>>58777276
this is not going to work because you declare x twice.
>>
>>58777327
>...
>int x = 9001;
>for (x = x; x < 10001; x++) ...
>really weird design, but works.

>"but works"

So OP is a fucking fagget
>>
>>58777305
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
>>
>>58777317
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.
>>
>>58777346
>"but works"
I'm 100% sure it's a wintard
>>
>>58777354
>you should be assigning some initial value to k and l before you use them
i do?
>k = 1024-128*i
>l = 0
>>
>>58777361
>>58777346
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.
>>
>>58777372
Oh, sorry, didn't see the updated code. I was looking at the one up top, where only if(i == l)
>>
>>58777387
that's if(i == 1), not if(i == l)
blame the font
>>
>>58777385
so please now, do this :

for (int i = x ; ......)
>>
>>58777359
"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?
>>
>>58777402
oh.... ok, then
>>
>>58777040
yes u can.
Wtf did you even try it?
Its 10 letters (including Compile key combination) vs three sentences and image copying.
>>
>>58777112
you can do
for (; x < 1000; ++x) 
>>
File: flow.jpg (15KB, 837x278px) Image search: [Google]
flow.jpg
15KB, 837x278px
>>58777412
why? i don't want an extra variable if i can use one that already has the value i need.

>>58777413
yes, correct. see pic
>>
>>58777465
Ok, what special operations must happen at the beginning and end?

Does it wrap around, or does it use a default value, like 0?
>>
>>58777445
nice! thank you, that is great
>>
>>58777477
it does the same at the end, it will go beyond data point 4096 and pad with 0 again
>>
>>58777066
stupid questions thread is what he means, but personally i dont think its a stupid question.
>>
>>58777486
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.
>>
>>58777584
wait, I think I screwed up something.

Let me actually make a dummy program.

I'm tired atm.

Gimme about 5 mins
>>
>>58777637
>>58777584
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.
>>
>>58777651
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
>>
>>58777792
it will always be in O(N2), it is nice though to have two for-loops combined into one like your second one
>>
>>58777854
oh? it's in c#
>>
>>58777792
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
>>
>>58777897
i'm too tired as well by now, can barely follow the logic in the algorithm anymore :)
>>
File: 4096Array.png (138KB, 1600x1740px) Image search: [Google]
4096Array.png
138KB, 1600x1740px
>>58777976
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 <stdio.h>

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;
}
>>
>>58778025
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.
>>
File: chuck-norris-thumbs-up.jpg (25KB, 379x247px) Image search: [Google]
chuck-norris-thumbs-up.jpg
25KB, 379x247px
>>58778050
>>58778025
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)
>>
>>58778117
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
>>
>>58777261
Have you tried
for(; x < limit; x++)
>>
>>58777445
>it took all these posts for someone to get it right
neo /g/
Thread posts: 52
Thread images: 6


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.