Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

For Loop

for (int i = 0; i < 5; i++) {
  System.out.println(i);
}
Comment

for loop

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

}
Comment

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
*/
Comment

for loop

//for iterating a certain number of times
for(j = 0; j < 20; j++){
  console.log(`do something for ${j + 1} time(s)`)
}
console.log("End of For loop")
Comment

for()

for (int i = 0; i < 5; i++) {
  System.out.println(i);
  
  // the integer name does not need to be i, and the loop
  //doesn't need to start at 0. In addition, the 10 can be replaced
  //with any value. In this case, the loop will run 10 times.
  //Finally, the incrementation of i can be any value, in this case,
  //i increments by one. To increment by 2, for example, you would
  //use "i += 2", or "i = i+2"
  
}
Comment

for loop

for (int i = 1; i <= 10; i++) {
	printf("%d
",i);
}
Comment

for loop

# continue statement and for loop

for a in range(0,10):
    if a**2 <=9:
        continue 
    print(a)
print('strain')
Comment

for loop

# example of forloop and return through factorial
def fact(m):# function factorial
    a=1
    for e in range(1,m+1):#we will be using for loop
        a*=e
    return a#return function
x= 5 # put the value in x eg, 5
d=fact(x)
print(d)

output:
120==5*4*3*2*1
-------------------------------------------------------------------------------
Comment

for loop

 double serviceCharge = 0;  if (cost >= 150)  
{  
   serviceCharge = 0.15 * cost;  
} 
Comment

for loop

for i in range (some_number):
	#code goes here
Comment

for loop

for i in range 10:
	print("hi")
Comment

for loop

# python
n=[10,1,20,1,5,56]     
for i in n:         
    print(i)      
                       
output:
10
1
20
1
5
56
Comment

for loop

for i in range(20)
	print(i)
Comment

for loop

#for loop
a=b=c=0
for m in range(0,10):
    a=int(input('the number1:'))
    b=int(input('the number2:'))
    if b==0:
        print('intermediate')
        break
    else:
        c=a//b
        print('the answer=',c)
print('conclusion')
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Comment

FOR Loop

For Loop
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times.
A for loop is useful when you know how many times a task is to be repeated.
Syntax : 
for(initialization; Boolean_expression; update) {
   // Statements
}
This is how it works : 

The initialization step is executed first, and only once. This step allows you to declare and initialize any loop control variables and this step ends with a semi colon (;).
Next, the Boolean expression is evaluated.  If it is true, the body of the loop is executed. If it is false, the body of the loop will not be executed and control jumps to the next statement past the for loop.
After the body of the for loop gets executed, the control jumps back up to the update statement. This statement allows you to update any loop control variables. This statement can be left blank with a semicolon at the end.
The Boolean expression is now evaluated again. If it is true, the loop executes and the process repeats (body of loop, then update step, then Boolean expression).  After the Boolean expression is false, the for loop terminates.
Comment

For loop

for( initialize; test; increment or decrement)

{

//code;

//code;

}
Comment

for loop

const n = 7; 

for(let i = 0; i <= n; i++) console.log(i);

// output -> 0, 1, 2, 3, 4, 5, 6, 7 
Comment

for loop

newlist = []

for word in wordlist:
    newlist.append(word.upper())
Comment

for loop

for i in 0..5 {
    println!("{}", i * 2);
}

for i in std::iter::repeat(5) {
    println!("turns out {} never stops being 5", i);
    break; // would loop forever otherwise
}

'outer: for x in 5..50 {
    for y in 0..10 {
        if x == y {
            break 'outer;
        }
    }
}
Comment

what are for loops

# There are 2 types of loops in python
# while loops and for loops
# a while loops continues for an indefinite amount of time
# until a condition is met:

x = 0
y = 3
while x < y:
    print(x)
    x = x + 1

>>> 0
>>> 1
>>> 2

# The number of iterations (loops) that the while loop above
# performs is dependent on the value of y and can therefore change

######################################################################

# below is the equivalent for loop:
for i in range(0, 3):
    print(i)

>>> 0
>>> 1
>>> 2

# The for loop above is a definite loop which means that it will always
# loop three times (because of the range I have set)
# notice that the loop begins at 0 and goes up to one less than 3.
Comment

for loop

a=5
b=2
for a > b:
a+=1
pint(a)
Comment

for loop

newlist = []

for word in wordlist:
    newlist.append(word.upper())
    
# instead, use this:

newlist = map(str.upper, wordlist)
Comment

for loop

<?php
	$counter=0;
	for($start=0; $start<11;$start++)
	{
		$counter=$counter+1;
		print $counter."<br>";
	}
//======output=====
/*
1
2
3
4
5
6
7
8
9
10
11
*/
		
?>
Comment

for loop

for ($i = 0; $i < 10; $i++) {
    echo "Value of i is: " . $i . "
";
}
Comment

for loops

#include <stdio.h>
int main()
{
   int i,j;
   for (i=1,j=1 ; i<3 || j<5; i++,j++)
   {
	printf("%d, %d
",i ,j);
   }
   return 0;
}
Comment

for loop

for(int i = 0; i < n; i++)
{
	sum += n;
}
Comment

for loop

//// Write a function that takes an array of objects (courses) and returns object of 2 new arrays // first one is containing the names of all of the courses in the data set. // second one is containing the names of all the students
const getInfo = (arr) => {
  let coursesName = [];
  let studentsName = [];
  // write your code here

  return { coursesName, studentsName };
};

//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
Comment

PREVIOUS NEXT
Code Example
Python :: python break 
Python :: python new line 
Python :: how to join an array of characters in python 
Python :: django test imagefield 
Python :: python while loop guessing game 
Python :: python - How to execute a program or call a system command? 
Python :: python logging level 
Python :: ord python3 
Python :: python import matplotlib 
Python :: creating numpy array using empty 
Python :: discard python 
Python :: scikit learn library in python 
Python :: how to run python in atom 
Python :: how to change the size of datapoint in plot python 
Python :: nltk hide download messages 
Python :: cronometro python tkinter 
Python :: intersection of two lists using set method 
Python :: Reading Custom Delimited file in python 
Python :: Python Alphabet using list comprehension 
Python :: Changing the data type to category 
Python :: how to add items to tuple in python 
Python :: megre pandas in dictionary 
Python :: Chef in his Office codechef solution 
Python :: how to sort in python 
Python :: why python stops after plt.show() 
Python :: change background create_text tkinter 
Python :: scikit learn decision tree 
Python :: recorrer lista desde el final python 
Python :: How to find the most similar word in a list in python 
Python :: python switch 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =