0
How for loop works?
How for loop works?
3 Answers
+ 2
Let's say you set up an array like:
fruits = ['banana', orange', 'grapefruit']
Then, let's suppose that you wanted to print out everything in that array in a nice formatted sentence. You could set up a for loop as follows:
for nameOfFruit in fruits:
print("I love", nameOfFruit)
For more information, you could check out https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_for_loop.htm
+ 2
For(initialization ;conditions ;increment /decrement)
In initialization you initialise a variable to specific value
In condition you specify a condition on which loop stops
Increment / detriment is used to increment value of the variableâ
Eg
For(i=0;i<5;i++)
cout<<i;
Here the I is initialized to 0 and is printed and increments iteration by iteration the output would be
1234
0
Loop is a sequence of instructions that is repeated until a certain condition is reached. A for loop has two sections: a header specifying the iterating conditions, and a body which is executed once per iteration . The header often declares an explicit loop counter or loop variable, which allows the body to know which iteration is being executed. More on...
http://net-informations.com/JUMP_LINK__&&__python__&&__JUMP_LINK/flow/for.htm