#Having a hard time what does this line exactly say?

1 messages · Page 1 of 1 (latest)

inland sky
#

Im not good at knowing what order to read

Why is the i at the end of the line? in an if header, that seems unusual

plucky vaultBOT
#

<@&987246399047479336> please have a look, thanks.

inland sky
#

shouldnt there be a { after the if parenthesis

tulip warren
#

yes but its allowed to leave it away if its just a single statement

#

but not recommended

inland sky
#

so it should be

if (i !=x) {

temp[pos++] = i;

}

plucky vaultBOT
tulip warren
#

so

if (A) B;
C;

// is the same as
if (A) {
  B;
}
C;
inland sky
#

and what comes next?

#

im confused sometimes by order of operatin

#

thats why i like to debug and so but

#

first we add the current i value to the position

#

wouldnt it be better to

if (i !=x) {

temp[pos] = i;
pos++;



}
plucky vaultBOT
inland sky
#

for readability?

#

first we add the value to current pos then we go to next pos

tulip warren
#

that foo[bar++] is another discouraged thing

#

cause its super confusing to readers

#

shouldnt be done

#

temp[pos++] = i;
works this way:

#

temp[x], then x++, then temp[thatOldXFromTheFirstStep] = i

inland sky
#

So first add then

#

Increase

tulip warren
#

nah in between

#

first thing that happens is that x is evaluated and temp[...] is captured

#

then x is incremented

#

then there is the assignment

#

example:
a[foo()] = bar() if u put prints into these methods ull see foo() called first, then bar()

#

and if u have a[x++] = x u would see that the x on the right side is incremented already. but on the left it isnt

#

so if x was 0 then this is essentially a[0] = 1

#

but as said, code like that is shit. dont write x++ or ++x in a situation like that

#

always put it on its own lonely line. then it's not confusing

plucky vaultBOT
#

@inland sky

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍

plucky vaultBOT
#

@inland sky

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure 👍