18 Replies
JavaBot
JavaBotā€¢16mo ago
āŒ› This post has been reserved for your question.
Hey @Mike B! Please use /close or the Close Post button above when your problem is solved. 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.
Mike B
Mike BOPā€¢16mo ago
Im trying to understand how to loop through this and why coffee is printing 10 times
JavaBot
JavaBotā€¢16mo ago
It looks like you are having issues with debugging or issues that can be solved using a debugger. Check out this article on dev.java to see how debugging works and how to use a debugger. This Stack Overflow question and its answers also explain debugging in general. These links describe how to use the debugger in some IDEs: ā€¢ Debugging in IntelliJ ā€¢ Debugging in Eclipse
Mike B
Mike BOPā€¢16mo ago
the part confusing me is that, yes it prints the first time but then j increases to 1 and then i is now greater than i so then i increases to 1 and then j goes to 2 and then i goes to 2 and so on
dan1st
dan1stā€¢16mo ago
you can step through it with a debugger and it will show you so?
Mike B
Mike BOPā€¢16mo ago
why does coffee print 10 times or atleast how does it
dan1st
dan1stā€¢16mo ago
In the first iteration, i is 0 so the inner loop is executed 0 timrs in the second iteration, i is 1, the inner loop/println os ececuted once
Mike B
Mike BOPā€¢16mo ago
ohh okay so it doesn't print the first time ohh okayyy totally makes sense thanks
JavaBot
JavaBotā€¢16mo ago
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.
dan1st
dan1stā€¢16mo ago
0<0 is false i is 0 and j is 0 so j<i is 0<0 which is false
Mike B
Mike BOPā€¢16mo ago
ohh okay and then if im correct
dan1st
dan1stā€¢16mo ago
but if you use a debugger, you can run it and it will show what exactly happens
Mike B
Mike BOPā€¢16mo ago
once it prints does j increase again or does it go back to the our loop and ok let me check that
dan1st
dan1stā€¢16mo ago
j increases with every itetation of the inner loop - and it resets every iteration of the outer loop
Mike B
Mike BOPā€¢16mo ago
ohh okay that makes sense wow so basically every time j > i it resets and the out loop then increases
dan1st
dan1stā€¢16mo ago
j is only valid in the inner loop after the inner loop ends, j is destroyed and it is created when the inner loop starts
Mike B
Mike BOPā€¢16mo ago
it all makes sense now thanks!!
JavaBot
JavaBotā€¢16mo ago
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. šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?