else if(strings.get(i).charAt(p)=='}') {
if(brackets.peek()=='{') {
brackets.pop();
}else { correctOrIncorrect.add(0);
break;
}```
im having some trouble understanding the logic here. While debugging iv noticed that when the `if` condition is false, the `else` condition does not get executed...may someone please explain why this is, or am i just understanding it in a wrong way?
#logic problem with if statement
42 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @hardy fractal! 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.
sorry, idk why the code looks messed up🥲 😅
which if?
also, are you sure it isn't getting executed? correctOrIncorrect.add(0); seems like a nop, i'd expect a correctOrIncorrect.add(1) there, without knowing what correctOrIncorrect is
when i try tp past the code it goes over the character limit im allowed...but yes, im sure its not getting executed because 0 is not being added. i understand its harder to find the error without looking at the whole thing, but i thought it would just be a logical issue involving the if statement, because according to what i know, if the if condition is false, the else condition should be executed, right?
yes
it might not be getting reached due to the else if above it being false, though.
which is why i asked
have you tried debugging
let me try pasting it again. Yes i have tried to debug it, thats how i saw its not being executed🥺
i hope it comes out looking right...
it says this😢
try a bin
is the if even getting reached though?
what does that mean lol🥲
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
these
yes it is. Can i try putting it in a note pad and sending that?
please don't use files
use these
if you dont mind me asking, what should i do after a new paste is created?🥲 😅
uh, send it here?
lol okay, let me just see how to send it...give me a sec😅
just copy the link
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
im sorry it looks so convoluted🥺 🤦
so what makes you think it isn't getting executed?
also doesn't look like you're resetting brackets after each loop
i think brackets is being cleared on lines 12-14?
oh my bad, completely missed that; something like that should be at the end of the loop, or just have brackets local to the loop. relying on the next iteration to handle a dirty state is error-prone.
i guess because i know from inspection that the condition should fail and hence go to the else condition, but i know when it comes to programming the computer is always right🥲 so maybe its a logic error on my part
understood👍
i feel like im missing a lot of context here on what specifically is the issue, the descriptions so far have been somewhat hard to interpret so im not sure im understanding correctly
are you saying neither the if nor the else are being executed?
im trying to make a program that checks if a string has the correct opening and closing brackets
Like ([)] would be wrong and (){[<>]} would be right
but in terms of those if statements im really not sure if i think i know exactly what the problem is...i may be just misunderstanding my own problem🥲
i see you have a system there for handling multiple strings, can you explain that part
basically im taking the string and placing it into an arraylist, and then the for loop uses the elements in that arraylist sequentially
the strings can look like
(((a * x) + [b] * y) + c which is wrong and auf(zlo)men [gy<psy>] four{s} which is right