Questions tagged [do-loops]

a 'do' loop is a specific type of iteration used to run code repeatedly based on the evaluation of a boolean statement or variable.

do (while) loops in Java: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html

do loops in Fortran: https://en.wikibooks.org/wiki/Fortran/Fortran_control#Loops

do loops in Scheme: https://schemers.org/Documents/Standards/R5RS/HTML/

389 questions
9
votes
6 answers

Alternative to "last" in do loops

According to the perl manual for for last (http://perldoc.perl.org/functions/last.html), last can't be used to break out of do {} loops, but it doesn't mention an alternative. The script I'm maintaining has this structure: do { ... if (...)…
DAG
  • 157
  • 1
  • 2
  • 6
9
votes
2 answers

Using "do" in Scheme

What is the difference between CODE SNIPPET 1 and CODE SNIPPET 2? ;CODE SNIPPET 1 (define i 0) (do () ((= i 5)) ; Two sets of parentheses (display i) …
Gautam
  • 1,732
  • 4
  • 18
  • 26
6
votes
4 answers

Random Number in a do-while loop with if statement

I am trying to get make a random number generator that generates a string of numbers between 1 and 9, and if it generates an 8, it should display the 8 last and then stop generating. So far it prints 1 2 3 4 5 6 7 8, but it does not generate a…
hannacreed
  • 639
  • 3
  • 15
  • 34
6
votes
2 answers

Skip iterations in a do-loop (fortran)

I want to loop over N iterations, but some of the iterations should be "skipped" under particular conditions. I know I can do it using the goto statement, such as : do i = 1, N if condition(i) goto 14 ! Execute my…
Feffe
  • 173
  • 1
  • 6
6
votes
1 answer

Lisp DO variable syntax reasoning

In Peter Seibel's Practical Common Lisp, he gives this example: (do ((nums nil) (i 1 (1+ i))) ((> i 10) (nreverse nums)) (push i nums)) I can see how it works, using nums inside the loop but not giving it a step-form. Why would you put nums…
JasonFruit
  • 7,764
  • 5
  • 46
  • 61
5
votes
3 answers

Using array member as the control variable of do loop in fortran

I was surprised that you cannot put a array member as the control variable of do loop like this: program test integer, dimension(2) :: i do i(1) = 1, 3 do i(2) = 1, 3 ! anything here write(*, *) i end do end…
5
votes
1 answer

Clarifying a fortran implied loop

I used FORTRAN a little, many years ago, and have recently been tasked to maintain an old FORTRAN program (F77). The following code was unfamiliar: READ(FILE_LOG_UNIT, IOSTAT=FILE_STATUS) NUM_WORDS, . ( BUFFER(BIX), BIX=1, NUM_WORDS…
5
votes
2 answers

Value of Fortran DO loop index after the loop

How do DO loops work exactly? Let's say you have the following loop: do i=1,10 ...code... end do write(*,*)I why is the printed I 11, and not 10? But when the loop stops due to an if(something) exit the I is as expected (for example i=7, exit…
why.n0t
  • 432
  • 7
  • 21
4
votes
2 answers

My vba loop pulls back all the correct data when I step through but when I run the Macro it does not

I have tried to build a loop that pulls back certain data when it meets a criteria, then posts the results in my 'Main' sheet. Unfortunately, when you run the macro it does not pull back all of the data. However, and this in my opinion is super…
Gboz
  • 41
  • 2
4
votes
1 answer

Scheme/Racket: do loop order of evaluation

The following procedure is valid in both scheme r6rs and Racket: ;; create a list of all the numbers from 1 to n (define (make-nums n) (do [(x n (- x 1)) (lst (list) (cons x lst))] ((= x 0) lst))) I've tested it for both r6rs and Racket…
Cam
  • 14,930
  • 16
  • 77
  • 128
4
votes
3 answers

VBA DO Loops Issue

I am trying to create a pop up question in powerpoint VBA, so far so good. But below code doesn’t seem to work. Idea is that you get a popup box with value to enter between 100 - 200 (inclusive). But must enter a value between or can accept failed…
rellik
  • 304
  • 1
  • 4
  • 16
4
votes
1 answer

SAS: Improving the speed of a do loop with proc import

I have over 3400 CSV files, with size varying between 10kb to 3mb. Each CSV files have this generic filename: stockticker-Ret.csv where stockticker is the stock ticker like AAPL, GOOG, YHOO, and so on and has stock returns for at every minute on a…
Plug4
  • 3,838
  • 9
  • 51
  • 79
3
votes
2 answers

why not use DO WHILE in Fortran

I'm studying Fortran from the book of Stephen Chapman "Fortran for Scientists and Engineers" (2018). In page 134, the author wrote this: Good Programming Practice: Do not use DO WHILE loops in new programs. Use the more general while loop…
baki
  • 41
  • 3
3
votes
2 answers

rename SAS variables in reverse order using do loops

I have 10 variables (var1-var10), which I need to rename var10-var1 in SAS. So basically I need var10 to be renamed var1, var9 var2, var8 var3, and so on. This is the code that I used based on this paper,…
llsabang
  • 143
  • 1
  • 10
3
votes
2 answers

SAS SQL Loop Inputting Sequential Files

I have: 6 files, named as follows: "ROSTER2008", "ROSTER2009", ..., "ROSTER2013" Each file has these variables: TEAMID and MATE1, MATE2, ..., MATEX. The names of the teammates are stored for each team, through to teammate X. Now: I want to loop…
Xtina
  • 33
  • 4
1
2 3
25 26