Answers for "how to do a for loop"

7

loops in python

#While Loop:
while ("condition that if true the loop continues"):
  #Do whatever you want here
else: #If the while loop reaches the end do the things inside here
  #Do whatever you want here

#For Loop:
for x in range("how many times you want to run"):
  #Do whatever you want here
Posted by: Guest on September-24-2020
6

for loop

// this is javascript, but can be used in any language 
// with minor modifications of variable definitions

let array = ["foo", "bar"]

let low = 0; // the index to start at
let high = array.length; // can also be a number

/* high can be a direct access too
	the first part will be executed when the loop starts 
    	for the first time
	the second part ("i < high") is the condition 
    	for it to loop over again.
    the third part will be executen every time the code 
        block in the loop is closed.
*/ 
for(let i = low; i < high; i++) { 
  // the variable i is the index, which is
  // the amount of times the loop has looped already
  console.log(i);
  console.log(array[i]); 
} // i will be incremented when this is hit.

// output: 
/*
	0
    foo
    1
    bar
*/
Posted by: Guest on December-16-2020
0

for loop

for (int i = 0; i <= 5; i++)
{

}
Posted by: Guest on October-08-2021
1

For loop

for( initialize; test; increment or decrement)

{

//code;

//code;

}
Posted by: Guest on August-22-2021
0

for loop

for (let i = 0; i < substr.length; ++i) {
    // do something with `substr[i]`
}
Posted by: Guest on April-20-2021
1

for loops

for (initialization expr; test expr; update expr)
{    
     // body of the loop
     // statements we want to execute
}
**Initialization Expression: In this expression we have to initialize the loop counter to some value. for example: int i=1;
Test Expression: In this expression we have to test the condition. If the condition evaluates to true then we will execute the body of loop and go to update expression otherwise we will exit from the for loop. For example: i <= 10;
Update Expression: After executing loop body this expression increments/decrements the loop variable by some value. for example: i++;**
Posted by: Guest on June-01-2021

Code answers related to "how to do a for loop"

Python Answers by Framework

Browse Popular Code Answers by Language