Please explain this loop:
for(p=0;p<a[j];p++)
I am a beginner and I am confused how do such loops work?
Please emphasize on use of a[j] in loop.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If
a[j]remains a constant positive number through each iteration of theforloop, the loop will run exactlya[j]times, wherea[j]evaluates to someinteger(orlong, we can’t tell from the code posted). Of coursea[j](orj) could be modified inside the loop. In any case, the loop terminates oncepis greater than or equal toa[j]when the loop condition is evaluated. The condition is checked before each iteration of the loop. Ifa[j]is zero or a negative number, the contents of theforloop are never executed. The loop can also exit prematurely at any time if there is a call tobreakorreturnwithin the loop.