Am I using the wrong loop or the loop wrong
I'm using java 17 and here's my loop
the 'for' is there to print out the 'i' question
then i want the 'while' loop to let you
type out guesses until you get the correct answer
and once you are correct it adds '1' to 'i'
so that it prints out the next question
as of now what i have before this code is just the q & a string and the scanner
and when I run it
it prints the first question
and every input after does nothing correct answer or not
for (int i = 0; i < questions.length;) {
System.out.println(questions[i]);
while (true) {
if (scanner.equals(answers[i]))
System.out.println("You are correct");
i =+ 1;
}
12 Replies
⌛
This post has been reserved for your question.
Hey @Phloof_boll! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
ur using the loop wrong
you dont need the for loop at all tbh
but u will need an if statement to check if i is smaller than questions length
how do i add the if check
i have this now
This message has been formatted automatically. You can disable this using
/preferences
.works pretty gud besides that it ends with index out of bounds
thats because you need to check
if i is lower than answers length
i mean
questions
or you could do like this
oohhh ok
i didn't know i can put something other than true in there
thanks
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
yes u can put a lot of statements inside that
nice it works perfectly thanks a bunch
Post Closed
This post has been closed by <@515999978540236810>.