I have been having this issue with p5js on multiple coding projects. Once I have two or more for-loops (they are not nested) in the sketch, nothing will execute AFTER the loop.
I worked around this issue in previous sketches by changing around the order and putting the for-loops last.
However, for my current sketch, I need a for-loop to build on information about arrays in the previous loop. I've even tried adding a simple shape after the loop and before. And the shape will only execute and render on the sketch when it is included BEFORE.
The code for my sketch is quite long but if it will be useful to include it I can.
Thanks for your help.
If the code after a loop is never executed it might mean that your loop never finishes.
I'd recommend using console.log() to debug instead of drawing shapes. This way you can also debug inside the for loop and see if it works correctly.
For example, you can do something like this
console.log("Before loop");
for (let i=0; i<5; i++) {
console.log(`Inside loop. Iteration ${i}`);
}
console.log("After loop");
This code will print
Before loop
Inside loop. Iteration 0
Inside loop. Iteration 1
Inside loop. Iteration 2
Inside loop. Iteration 3
Inside loop. Iteration 4
After loop
As you can see, it's very easy with this code to see that the log before the loop is executed, that the loop executes 5 times and finally the log after the loop is executed.
Put something like this in your code and it will help looking where the code fails.
Related
I have looked around but I can't seem to find that information anywhere so I guess this is not possible
but I would like to be sure.
Is there a way to break out of a loop when using lldb ?
(And if not why has it not been implemented ?)
Debug information doesn't encode source constructs like loops, if branches, etc. That's been true of all the debug formats I've had to do with. So there's really no way that lldb could implement step out of loop - it has no way to know that loops are a thing.
The cleanest way to do this, when it's possible, is to set whatever condition the loop is checking to the "stop looping" value. Then set a breakpoint outside the loop and continue and the iteration you are in will be the last iteration.
You can also use the thread jump command to move the PC out of the loop, continuing from that point. Be very careful using this, however, as it's easy skip over some code you probably should have run. For instance if there were objects scoped to the loop, they won't get destroyed if you jump the PC to some line outside the loop.
If you know line, where loop ends, you can step out of loop with thread until <line>.
This is the same as setting temporary breakpoint in <line> but only one time.
I have a sample code :
#include<iostream>
main()
{
int i = 10; //Line 1
std::cout<<" i : "<<i; //Line 2
}
I want to somehow insert another statement (lets say one more std::cout) between Line-1 and Line 2.
Direct way is to change the source code and add required line. But for my source code compilation takes lot of time, so i can't afford to change the code frequently. So i want an automatic way such that i will be able to execute any statement in any function from outside so that upon hitting that function it execute my newly given statement.
I am not sure if this is possible or not. But any direction in writing the original code in such a way that my requirement can be fulfilled would be helpful.
[for debugging prupose]
If you want new C++ code to be executed, it must first be compiled. I don't think you can avoid that. You can however try to reduce how long the compilation takes, through various practices such as using header guards and being selective with headers.
There is a lot you can do in gdb to modify the behaviour of your program when it hits a nonstop breakpoint. The print command can also be used to change values, eg print i=0 actually sets i to zero.
Just remember that all these changes and hacks need to be ported back into the source code and tested again! I have lost many excellent edits over the years doing inline hacks in running code, and then exiting without reviewing the changes.
This question already has answers here:
Decrementing a loop counter as loop is executing
(3 answers)
Closed 7 years ago.
Can someone explain me this?
for i = 1, 5 do
print(i)
i = i - 1
print(i)
end
Output is:
1
0
2
1
3
2
and so forth
I exspected i to alter between 1 and 0. But obviously it keeps increasing as if I did not change it at all. What's going on?
I have to delete an i'th table element every now and then. So the next element to process would be i again. In C I would just write --i at the end of my loop content. Any official way in lua? :)
The loop index (i in your case) is a variable local to the body of the loop, so any modifications you do to it have no effect on the loop conditions or the next element being processed (for the for loop).
If you need to have better control over the index to delete elements and keep processing, you should use the while loop form. See For Statement section for details.
What about using a while(true) loop instead? Then you'll have to break manually, but that might work.
local i = 5
while(true) do
print(i)
i = i - 1
if (i == 0) then break; end
end
Attempting to set the loop control variable causes a failsafe behavior.
I can't find it in the Language Incompatibility section of recent versions of the manual but I recall it being listed somewhere as a change. It was more of a formalization of previous undefined behavior.
If you are really curious, see the listing of your program from luac. The loop control variable is given an internal name so it can't be changed. If the same name is used in an assignment, a local variable is synthesized as a stand-in. It prevents unintentionally causing the for to become infinite.
You need another kind of loop.
My code, as written, works for all the ways I've tested it. I have two questions though. First, Why in the blue blazes do I HAVE to use Do While loops instead of For loops in my code? I've searched Everywhere I can to help me on this issue. I can't reinstall excel, but I've reset as many of the settings as I can, but, invariably, the compiler skips over every for loop I have that isn't a for each loop... Except the first for loop in my programming... It is the weirdest and most bizarre behavior I have ever seen. I have used step through (F8) 10000 times to try and figure out why it keeps skipping. But every single time i make a for loop, it doesn't even run the first line of it.
To be clear, every place I have a Do While ... Loop, it SHOULD be a For Next. But making this change breaks the code every time because every spot the do while is changed to for, the code is skipped entirely. Even if I reset the i value to 0. The issue happens even if I have a different iterator for each loop.
Running w8 on an Intel i5 with Office 2010.
For i=1 To i = 100
If (i >= startRow And i <= stopRow And Not rowDone(i) And Not i = colFocus) Then
colCurPayAmounts(i) = S_Debt.Cells(i, 5)
Else
colCurPayAmounts(i) = 0
End If i = i + 1
Next i
The problem is it should be For i = 1 To 100 and not For i = 1 To i = 100 #Rory
if I generate Tubes in a loop like here
http://jsfiddle.net/crizzis/RYQty/1/
for (var y = 0; y < 800; y++){...}
The loop is starting to hang and will not finish, despite the main memory seems ok (Task Manager) and the GPU Memory seems to be fine as well.
It hangs in the loop where the tube geometry is generated. It is not even rendered.
Does anyone know how this can happen?
Strange thing is 700 loops are Performing within 5 seconds, 800 loops not at all or really, really slow.
Well, i just looked at your fiddle and i am not sure about your whole loop.
You are creating WAY too much stuff inside your loop. See for example the material. Just create it once outside the loop.
Then move the vector[0] and [1] definitions outside of the loop and inside the loop do vector[0].y = . So you don't create 2 Three.Vector3()-objects for every run. Also, move all variable declarations outside your loop. Just something like var line; and inside, you do line = SPline...
Next, why don't you just create the whole Spline inside the loop and then AFTER the loop, create ONE TubeGeometry afterwards instead of creating hundreds of meshes? Well, I don't know your usecase anyway.