Learn Python Training from the Best Tutors
Search in
There may be a typo in the question. however this could be the corrected question.....
for (I=0, j=n; I<n; I++, j--)
>>> # for (I=0, j=n; I<n; I++, j--)
>>> j=n=10 # we initialize 'n' and 'j'
>>> # i<10 is the terminating condition, so we loop 'n' times.
>>> for i in range(n):
#in your case you are incrementing i by 1 repeatedly
#and in the end i==n. j will be decremented by 1, n times.
#In Python, we simulate the 'for' loop with range() and the the Range object will have a
#sequence of int objects from 0 to 9. (ie.n-1). The 'for' construct will iterate thru the
#Range object according to its size and stop,after which it will execute the 'else' block.
#In Python, 'else' is an independent construct that can be used when ever a condition is checked.
#'else' will execute when a condition is 'False'. We initialize 'n' and 'j' outside the 'for' construct.
#The range() will construct a Range object of ints from 0 to n. All we need to do is decrement j.
#On successful completion of the 'for', the 'else' will execute. Here, we add 1 to 'i' to make i==n.
j-=1
else:
i+=1
print('i= ',i,'\n','j= ',j)
i= 10
j= 0
>>>
Related Questions
I am working in a nontechnical field and i want to switch this job and work in a technical field but I am not able to decide where to start. I want to learn, but what in Python?
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Top 5 reasons why you should learn Python
Python is one of the most popular programming languages in the world. It is general-purpose, object oriented, high-level programming language used in a number of programming fields. Python is a great programming language to learn as it will introduce you to the world of programming. If you are from the technical background...
What is Applications Engineering all about?
Applications engineering is a hot trend in the current IT market. An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...
Learn Hadoop and Big Data
Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...
Learn Microsoft Excel
Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...
Looking for Python Training classes?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for Python Training Classes are on UrbanPro
The best Tutors for Python Training Classes are on UrbanPro