Help solving an example program (C - Nested Loops)
Go to solution
Solved by Stardar1,
OK, I'm going to trace the code for you.
running through the first loop, I is 0, which satisfies the condition and goes into the loop.
now we enter the second loop, as 0<3 for J
here, we print the first "Two"
now we loop through the second loop again, J is now 1, and 1<3
here we print the second "Two"
now, J is 1 and I is 0, which satisfies that if statement, so we break from the second loop.
we then print "One"
we go back to the first loop, i is now 1, j is 0 again, we print another "Two"
the if statement is true again, so we break from the loop and print the "One" again.
I no longer satisfies the condition, so we dont loop again
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now