#Will my for loop keep running after the catch block catches an exception
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @junior sedge! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
the try/catch is executed once for every iteration of the loop, it has no bearing on the iteration of the loop
unless i add a break;
inside catch right
cuz i want to stop it from looping if it catches an error
catch an error - > delete placed tiles -> stop the looping
put the for in the try then
that will still k++ ?
why delete placed tiles? you shouldntve placed them if it's an invalid state
it checks one tile by one tile, to see if they respect the rules, and if one doesnt then remove the others
why not just check all of them, and only if they all pass, place all of them
why worry about cleanup when you can just not create a dirty state to begin with
the dirty state is needed
im placing a line of tiles
no, not really
the first 3 could respect the rules
but the last one no
it already doesnt place them if the rules are easy to detect
yeah so only place them after you've checked all the tiles
so just.. do that here
having a consistent system will make it much easier to work with
could use streams
The basic checks like: 2 tiles in same line identical, 2 tiles in same line have different shape AND color, tile in line place already occupied by another tile, line of tiles placed somewhere where there isnt any other tile near. These basic checks dont place the tiles they just throw exception.
The hard check is the one where im checking in the grid in the line they will be placed if there is another tile touching with different color and shape
and for that i must place the tiles, so I can iterate through the whole line
otherwise around it its null
and it throws an exception
you really don't
you can just check each tile in the sequence of tiles that are about to be placed there
so handle that.
https://xyproblem.info you're just making it harder for yourself
Asking about your attempted solution rather than your actual problem
the obvious solution has a trivial issue, and your reaction is to discard it and mix in a completely different way of doing things?
its not a trivial issue because there could be other lines involved
for example
this placement here is incorrect
the way im doing things right now
it places the blue square up there because that one is valid
and then the circle it checks for it
that is kinda trivial though
i have no idea what the check actually is because you're so vague about it, but i assure you, it's much easier than fumbling with partial/dirty state
Im not trying to be vague at all
then maybe try to be more specific
sec
either way, you're going down the wrong path, just continue along the path you've been going down before
nope don't want to hear it
don't ask me to be specific then
anyways
this placement here is valid
even tho 2 identical tiles are on the same line in the grid
because they arent touching each other nor touching another line with the same tile
so i must check if there is a null everytime im checking, because when i find the null it means im done with the line and all gucci
except when trying for a line if i dont actually place the tiles itll detect nulls
because the path they got placed in is not there
and its important to place them because the tile at position 5 could perfectly be touching another line
so its not enough by just checking the line they got attached to
aight ok let me be clear.
be more specific next time
imma just be blunt, you need to figure out how to ask better questions, give enough info to actually be helped
but this help thread doesn't need that, there's not really anything more to add. you can implement the checks without a partial state just fine, whatever they may be
you can check for that without placing them.
you could technically yes, by saying if the direction im checking is the opposite as the one i placed them in then start the check where the first tile got checked
but thats more work than just placing and checking
and if invalid remove all
it isn't
innocent until proven guilty
you're just being stubborn now
no I actually believe it is more work
or maybe it isnt for the machine
for the machine its maybe less work
but for the human brain im carrying it is more work
but then again the point is to make it less work for the machine i guess
ok but
- it isn't.
- this is conflicting with your existing design. this is how spaghetti code is born.
- this is much less safe, just by nature of partial states.
- it's more bug and error prone.
it's less work to implement because it reuses other parts of your design, and it saves you work fixing the damn thing
but sure go make your spaghetti code if you so believe it's less work
even if making the code you refer to would require a whole new method to treat multiple tiles ?
because by doing this "spaghetti code" im allowing myself to reuse the code that checks for one tile
you can reuse code here too, yknow
again, you're making it out to be harder than it actually is
im done here
I just rewrote it by not placing the tiles
I wrote much more lines but hey
if its better to write 10 extra lines than to have spaghetti code
why not