0

How for loop works?

How for loop works?

26th Jan 2017, 3:43 PM
Amita Mishra
Amita Mishra - avatar
3 Respostas
+ 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
26th Jan 2017, 4:03 PM
James Hall
James Hall - avatar
+ 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
26th Jan 2017, 5:18 PM
Jayvardhan Deshmukh
Jayvardhan Deshmukh - avatar
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
7th May 2019, 5:31 AM
rahul kumar
rahul kumar - avatar