tagged [for-loop]

Is it possible to implement a Python for range loop without an iterator variable?

Is it possible to implement a Python for range loop without an iterator variable? Is it possible to do following without the `i`? If you just want to do something N amount of times and don't need the ...

29 Jul at 13:50

How to loop through key/value object in Javascript?

How to loop through key/value object in Javascript? now I want to create a `setUsers()` method that takes a key/value pair object and initializes the `user` variable. where data is like:

How do I put two increment statements in a C++ 'for' loop?

How do I put two increment statements in a C++ 'for' loop? I would like to increment two variables in a `for`-loop condition instead of one. So something like: What is the syntax for this?

17 Apr at 13:3

What is the difference between for and foreach?

What is the difference between for and foreach? What is the major difference between `for` and `foreach` loops? In which scenarios can we use `for` and not `foreach` and vice versa. Would it be possib...

16 Dec at 05:22

List append() in for loop raises exception: 'NoneType' object has no attribute 'append'

List append() in for loop raises exception: 'NoneType' object has no attribute 'append' In Python, trying to do the most basic append function to a list with a loop: Not sure what I am missing here: r...

23 Jul at 11:2

Performance difference for control structures 'for' and 'foreach' in C#

Performance difference for control structures 'for' and 'foreach' in C# Which code snippet will give better performance? The below code segments were written in C#. 1. ``` for(int tempCount=0;tempCoun...

20 Jan at 23:8

What does the colon (:) operator do?

What does the colon (:) operator do? Apparently a colon is used in multiple ways in Java. Would anyone mind explaining what it does? For instance here: ``` String cardString = ""; for (PlayingCard c :...

19 Jan at 15:15

How to loop through each row of dataFrame in pyspark

How to loop through each row of dataFrame in pyspark E.g The above statement prints theentire table on terminal. But I want to access each row in that table using `for` or `while` to perform further c...

Use of "for (;;)" in a C# application?

Use of "for (;;)" in a C# application? I've been looking through some sample source code for an application I use and I came across this line: It looks like this is to create an infinite loop, but I'm...

5 Jan at 13:25

Python - How to concatenate to a string in a for loop?

Python - How to concatenate to a string in a for loop? I need to "concatenate to a string in a for loop". To explain, I have this list: And inside a for loop I need to end with this: Can you give me a...

23 Nov at 21:55

Creating for loop until list.length

Creating for loop until list.length I'm reading about for loops right now, and I am curious if it's possible to do a for loop in Python like in Java. Is it even possible to do something like ``` for (...

29 Oct at 13:55

C++ Loop through Map

C++ Loop through Map I want to iterate through each element in the `map` without knowing any of its string-int values or keys. What I have so far:

Exiting out of a FOR loop in a batch file?

Exiting out of a FOR loop in a batch file? Why does this batch file never break out of the loop? Shouldn't the `Goto :EOF` break out of the loop? ### Edit: I guess I should've asked more explicitly......

20 Jun at 09:12

Is it possible to declare two variables of different types in a for loop?

Is it possible to declare two variables of different types in a for loop? Is it possible to declare two variables of different types in the initialization body of a for loop in C++? For example: defin...

22 Apr at 00:53

"for loop" with two variables?

"for loop" with two variables? How can I include two variables in the same `for` loop?

19 Jan at 02:16

While, Do While, For loops in Assembly Language (emu8086)

While, Do While, For loops in Assembly Language (emu8086) I want to convert simple loops in high-level languages into assembly language (for emu8086) say, I have this code: ``` for(int x = 0; x

Technical reasons behind formatting when incrementing by 1 in a 'for' loop?

Technical reasons behind formatting when incrementing by 1 in a 'for' loop? All over the web, code samples have `for` loops which look like this: ``` for(int i = 0; i

22 Jul at 10:20

Never seen before C++ for loop

Never seen before C++ for loop I was converting a C++ algorithm to C#. I came across this for loop: It gives no error in C++, but it does in C# (cannot convert int to bool). I really can't figure out ...

8 Jan at 13:45

How can I use break or continue within for loop in Twig template?

How can I use break or continue within for loop in Twig template? I try to use a simple loop, in my real code this loop is more complex, and I need to `break` this iteration like: How can I use behavi...

29 Dec at 07:6

Breaking/exit nested for in vb.net

Breaking/exit nested for in vb.net How do I get out of nested for or loop in vb.net? I tried using exit for but it jumped or breaked only one for loop only. How can I make it for the following:

25 Feb at 11:3

Get current index from foreach loop

Get current index from foreach loop Using C# and Silverlight How do I get the index of the current item in the list? Code: ``` IEnumerable list = DataGridDetail.ItemsSource as IEnumerable; List lstFil...

27 Apr at 08:9

Do an action only if a condition is met in all iterations of a loop

Do an action only if a condition is met in all iterations of a loop Is there a way to only trigger an action when a condition is met in iterations of a `for` loop? Example: This is what I tried, but i...

13 Aug at 13:4

For loop to calculate factorials

For loop to calculate factorials Currently I have this set of code and its meant to calculate factorials. ``` int numberInt = int.Parse(factorialNumberTextBox.Text); for (int i = 1; i

16 May at 10:2

How to efficiently remove all null elements from a ArrayList or String Array?

How to efficiently remove all null elements from a ArrayList or String Array? I try with a loop like that But it isn't nice. Can anyone suggest me a better solution? --- Some useful benchmarks to make...

While loop in batch

While loop in batch Here is what I want, inside the `BACKUPDIR`, I want to execute `cscript /nologo c:\deletefile.vbs %BACKUPDIR%` until number of files inside the folder is greater than 21(`countfile...