Questions tagged [loop-counter]

18 questions
267
votes
15 answers

When to use std::size_t?

I'm just wondering should I use std::size_t for loops and stuff instead of int? For instance: #include int main() { for (std::size_t i = 0; i < 10; ++i) { // std::size_t OK here? Or should I use, say, unsigned int instead? …
nhaa123
  • 9,570
  • 11
  • 42
  • 63
16
votes
7 answers

Should I expect to see the counter in `for` loop changed inside its body?

I'm reading someone else's code and they separately increment their for loop counter inside the loop, as well as including the usual afterthought. For example: for( int y = 4; y < 12; y++ ) { // blah if( var < othervar ) { y++; …
volvox
  • 3,014
  • 16
  • 51
  • 80
7
votes
7 answers

Why does Pascal forbid modification of the counter inside the for block?

Is it because Pascal was designed to be so, or are there any tradeoffs? Or what are the pros and cons to forbid or not forbid modification of the counter inside a for-block? IMHO, there is little use to modify the counter inside a…
Jichao
  • 40,341
  • 47
  • 125
  • 198
6
votes
5 answers

Any risk of using float variables as loop counters and their fractional increment/decrement for non "==" conditions?

Are we safe to use floats as loop-counters and to increment/decrement them by fractional amounts at each iteration,like in the seemingly risk-free program below?Of course I know that using floats as operands for the == operator is a dumb thing to…
3
votes
3 answers

Is it possible to use a for loop to change a variable name in C?

This is a generic question, so there is no actual code that I am trying to troubleshoot. But what I want to know is, can I use a for loop to change the name of a variable in C? For instance, if I have part1, part2, part3, part..., as my variable…
Jason Golightly
  • 71
  • 1
  • 1
  • 7
1
vote
1 answer

JMeter threads run once while loop counter set to 'forever' with constant throughput timer

I have a test plan in JMeter that tests a memSQL db, which seems to be running each thread only once, instead of running forever. It has 3 thread groups. Each has its own JDBC request element (1 for a delete, 1 for an insert, 1 for a select). I…
Nexaspx
  • 371
  • 4
  • 20
1
vote
2 answers

Confusion between loop count & number of threads and query regarding the thread life span

What is the difference between the below 2 scenarios and will it have similar performance impact? What will be the delay between requests in scenario 2? Will all the threads remain alive in Scenario 2? I'm aware of the fact that thread simulates a…
user2044296
  • 504
  • 1
  • 7
  • 18
1
vote
1 answer

C loop with steps smaller than 1

So I'm wondering, how do I make sure that all steps in a loop are performed if the step size is smaller than 1? Take this loop for instance: for (float y, x = -1.0; x <= 1.0; x += 0.1) { y = (4*x*x*x) + (3*x*x) + (5*x) - 10; …
1
vote
1 answer

What is the name for the iterative paramater in a for loop in context of graphs?

Suppose you have a function that iterates x value over some kind of a range or an interval, like so: for (x = MIN_CONST; x <= MAX_CONST; $x += STEP_CONST) { //x is a ____ (what)? y = library_function(x); print y } An x value (out of…
Dennis
  • 7,907
  • 11
  • 65
  • 115
1
vote
1 answer

Python 3.3 Inner Nested While Loop Not Outputting

I'm trying to learn Python between self thought of projects relevant to me and utilizing teamtreehouse though it's slow progress. Goal: Have inner loop calculate the cost of an individual class semester in one year then print that out. This inner…
L2g2h
  • 35
  • 8
0
votes
1 answer

Loop counter returning 0

Sorry if this is a bit silly I am new to coding. I tried creating a confusion matrix, I used the unique function and then created a null matrix and tried adding loop counters to be able to determine time-complexity but it returns 0. I think it is…
0
votes
0 answers

Python Loop counter returning 0

I am coding a decision tree and a confusion matrix and I added loop counters to determine the run time of my code but it returns me 0. L = 0 def creatematrixnull(target): global L uniquetarget =unique(target) # we specifie the type to…
user18269591
0
votes
1 answer

Run user defined in csv; for the number of loop defined In Thread Group -Jmeter

Scenario: CSV File contains 5 Username and Password and below are the settings Recycle on EOF: false Stop thread on EOF: true Sharing Mode: Current Thread Group Total there are 3 thread group below are the settings: Thread 1…
Dipak
  • 53
  • 8
0
votes
1 answer

how to test condition properly: je or jge

I sometimes use this pattern to iterate array of something: mov [rsp+.r12], r12 ; Choose a register that calls inside the loop won't modify mov r12, -1 .i: inc r12 cmp r12, [rbp-.array_size] je .end_i ; ... program logic ... …
Bulat M.
  • 680
  • 9
  • 25
0
votes
2 answers

Can the internal counter of a Scratch Repeat block be accessed?

I assume that the Repeat() block in Scratch has some kind of internal counter that increments or decrements at the beginning or end of each time around the block. Can the value of this counter be accessed in any way? I realize this can be done to…
Adám
  • 6,573
  • 20
  • 37
1
2