Tag: loops

65 votes
15 answers
1.2K views
Looping through the content of a file in Bash

How do I iterate through each line of a text file with Bash? With this script: echo "Start!" for p in (pepti

avatar
Eddie
0 1 0 9
asked 07 September, 2021
63 votes
6 answers
448 views
How to concat string + i?

for i=1:N f(i) = 'f'+i; end gives an error in MatLab. What's the correct syntax to initial

avatar
Jeff
0 1 0 9
asked 07 September, 2021
52 votes
2 answers
2.2K views
Why does this Jython loop fail after a single run?

I've got the following code: public static String getVersion() { PythonInterpreter interpreter = ne

avatar
Clarice
0 1 0 9
asked 07 September, 2021
52 votes
23 answers
2.7K views
Accessing the index in 'for' loops?

How do I access the index in a for loop like the following? ints = [8, 23, 45, 12, 78] for i in ints: pri

avatar
Hildegard
0 1 0 9
asked 07 September, 2021
49 votes
30 answers
2.8K views
How do I break out of nested loops in Java?

I've got a nested loop construct like this: for (Type type : types) { for (Type t : types2) {

avatar
Don
0 1 0 9
asked 07 September, 2021
56 votes
3 answers
1.8K views
Why is printing "B" dramatically slower than printing "#"?

I generated two matrices of 1000 x 1000: First Matrix: O and #. Second Matrix: O and B. Using the following

avatar
Shantay
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
2.2K views
JavaScript closure inside loops – simple practical example

var funcs = []; // let's create 3 functions for (var i = 0; i < 3; i++) { // and store them in f

avatar
Shanita
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
1K views
How do I loop through or enumerate a JavaScript object?

I have a JavaScript object like the following: var p = { "p1": "value1", "p2": "value2", "p3": "v

avatar
Santiago
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
409 views
Loop through an array in JavaScript

In Java you can use a for loop to traverse objects in an array as follows: String[] myStringArray = {"Hello",

avatar
Charis
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
954 views
For-each over an array in JavaScript

How can I loop through all the entries in an array using JavaScript? I thought it was something like this: f

avatar
Cortez
0 1 0 9
asked 07 September, 2021
69 votes
7 answers
1.9K views
How does PHP &apos;foreach&apos; actually work?

Let me prefix this by saying that I know what foreach is, does and how to use it. This question concerns how i

avatar
Leonardo
0 1 0 9
asked 07 September, 2021