34 Replies
how can i make it so the error at the bottom doesnt happen?
they only exist within their for loops, u would have to declare them outside and before.
so something like
but what do u try to achieve here?
i
will be the same value as width
and j
same as height
because that if/else is after all the loop iterations are donei get this then ;-;
this is the assignement i was given
yeah, because now u try to declare it twice (once at the top and once in the loop), so in the loop u do not have to declare them any more
declaration in loop:
declaration outside of the loop
how would i change the for loop to not declare it inside?
OHHH
wait a sec
ahh
i then get this?
aah, yes, thats because the compiler isnt smart enough to know that the outer for loop will run at least once, so it doesnt see that
for (j = 0;
would have happenedah because its a nested loop?
yep
how do i make it so it works then? ;-;
instead of just
int j;
u could initialize it with int j = 0;
oooo ok that runs without any errors which is good, however it doesnt make the red and yellow pattern
oh here at the end
hm, hard to explain without spoonfeeding the answer
so basically ur code is executed sequentially from top to bottem right?
(the for loops repeat a couple steps ofc)
yeah
and with the for loops u print the rectangle, right?
yeah?
do i put it in the for loop?
yep
ooooooooooooo i see!
ok perfect it works! thanks a ton!!!!
thats also the only reason why u had the CS0103 errors
i see
so basically u can reverse ur code to declaring the variables in the loops again because u only need them in there
ok that makes perfect sense
you're a lifesaver, thanks again <a:BE_Yayy:1086338828333228032>
glad i could help o7
and one last tip, regarding the code when u declared
i
and j
outside of the loops:
its good practice to declare them close to where u use them, so in that case that would have been directly above for loopsooo that makes sense, just to make it easier to read and stuff
yeah, because its one semantic block
yeah gotcha!
if u dont have any more questions regarding this topic, then please $close the thread
Use the /close command to mark a forum thread as answered
😄
!close
Closed!