Questions tagged [loops]
A **loop** is a sequence of statements which is specified once but which may be carried out several times in succession.
154
questions
2
votes
2
answers
3k
views
Efficiency considerations: nested loop vs recursion
I would consider myself an intermediate Python programmer. One of my recent challenges was creating a list of all possible solutions to a given
Countdown problem.
Without getting into too much detail,...
0
votes
1
answer
139
views
how to reach all nodes in a Tree Structure where end of the tree is unknown
There is a XML link, which provides the children of any parentID given.
http://www.browsenodes.com/xml.php?action=BrowseNodeInfo&node=1036592
Then you can run the URL again with a children ID ...
9
votes
9
answers
13k
views
Clear way to skip the first element in an index based for loop
I have a for loop where I must skip the first element in a zero-based array.
Which of these shows my intentions more clearly?
for($i=1 ; $i < count(array) ; $i++){
array[$i];
}
or
for($i=0+...
3
votes
3
answers
392
views
Is loop unrolling one of the examples of "targeted" compilation and faster instruction set?
I'm taking the Computer Architecture course in my undergraduate study.
I see that in loop unrolling, one of the constraints is the number of available registers.
Since the number of registers ...
2
votes
2
answers
1k
views
How to update a player's money count every second
I'm in the process of analysis for a browser-based game I'm making, and I have question about programming the economy system. I'll use a simplified system to ask my question.
Each user as GameState ...
9
votes
2
answers
11k
views
Is it good practice to use array.pop() assignment in a while loop condition?
Just saw a code snippet that used an array pop assignment in the while condition; was wondering if this is acceptable/good practice?
var arr = [0,1,2,3,4,5];
var current;
while (current = arr.pop())
{...
-1
votes
3
answers
507
views
Time complexity of an algorithm [closed]
What is the complexity of the following loop?
for(i=1;i<n;i=2^i)
sum+=i;
1
vote
2
answers
133
views
Should I be Using a Thread?
I made a console application which makes the mouse click in the middle of the screen every two minutes. It has a while True loop in it which is meant to keep going for relatively long periods of time (...
46
votes
11
answers
31k
views
Is a while loop intrinsically a recursion?
I wondered whether a while loop is intrinsically a recursion?
I think it is because a while loop can be seen as a function that calls itself at the end. If it is not recursion, then what is the ...
5
votes
3
answers
5k
views
Is implementing IEnumerable required to use foreach on collections?
I have the following class that doesn't implement IEnumerable but is working perfectly with foreach.
And also, arrays are working without implementing IEnumerable.
So why does it keep saying that ...
4
votes
2
answers
652
views
Common loop variable names for indexes in 4D and above
I am curious if there are common loop index variables (of single character or not) for dealing with 4 dimensions and above?
I was helping another student working through CS50x who was just learning ...
-2
votes
1
answer
277
views
For loop and recursion for a new shell in C [closed]
I code a new shell in C, that could be done in several ways: Flex/bison, finite state machine, abstract syntax tree or just a tokenizer in C. Now I've written a for-loop that changes the condition of ...
21
votes
1
answer
6k
views
What is priming the pump? Sometimes called a priming read
I was taught this expression and pattern way back in the day. Sure, the name comes from old pumps that needed to be filled with water before they could pump water, but who cares? We're talking about ...
68
votes
17
answers
23k
views
How to write correct loops?
Most of time while writing loops I usually write wrong boundary conditions(eg: wrong outcome) or my assumptions about loop terminations are wrong(eg: infinitely running loop). Although I got my ...
-3
votes
1
answer
4k
views
Using System.out.println() with loops and arrays [closed]
Is there anyway I can create a loop for System.out.println("...") and reading in the values? For example I wish to do this:
System.out.println("Input the Executive's name: ");
String eName = ...