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
2
votes
3 answers

Simple Do-Loop: Checking to see if the row data before is the same

I'm used to coding in MatLab, SAS is still new to me when using Do Loops. My goal is to check the row above/before the current row to see if the current and previous row numbers match. If the vector data above the first row matches the current row,…
Sarah Reinke
  • 57
  • 3
  • 9
2
votes
2 answers

How to calculate conditional cumulative sum

I have a dataset like the one below, and I am trying to take a running total of events 2 and 3, with a slight twist. I only want to count these events when the Event_1_dt is less than the date in the current record. I'm currently using a macro %do…
2
votes
1 answer

renaming a set of variables in SAS with DO loop

I've been trying to rename a set of variables from a scale using arrays and DO loops, but without success. This seems like a very simple task. Any advice on where I'm going wrong? ARRAY ATRSS (i) ATRSS_1 ATRSS_12 ATRSS_13 ATRSS_25 ATRSS_29 ATRSS_30…
jme6f4
  • 43
  • 2
  • 6
2
votes
2 answers

Limit do-while to running 7 times unless given the correct input

I was having trouble getting the do-while loop to stop after the user has attempted to guess the number 7 times. I'm not sure exactly how to tell the loop to stop and display the timeout message. Thank you, I appreciate any help! Code: import…
Pejmon H.
  • 37
  • 1
  • 5
2
votes
5 answers

Do loop with unequal increment

I have a lot of sas dataset files that starts with "s" followed by some numbers like s1 s7 s13 s32 etc. (I have a lot). For each files I run a set of codes, save my last result and then restart with with the following dataset file. Normally, when my…
Plug4
  • 3,838
  • 9
  • 51
  • 79
2
votes
2 answers

Why does this Mathematica 7 Do loop work sequentially, but generates errors in parallel (using ParallelDo)?

I am running Mathematica 7, and I am trying to run a simple Do loop in parallel, using ParallelDo. The following standard, sequential code works fine: len = 10; A = Table[0, {len}]; Do[ A[[i]] = i*10; , {i, 1, len}] However, if I use…
Andrew
  • 1,499
  • 9
  • 25
  • 37
1
vote
4 answers

Java - do loop help explaining needed

Why does the following code execute six times? Please help me to understand how this works, as I've tried to get it into my head without success. I thought it would first execute the code once, then increase count to 1, execute it a second time,…
mino
  • 6,978
  • 21
  • 62
  • 75
1
vote
2 answers

Object reference not set to an instance of an object? VB.NET

I have this code here: Dim MasterIndex As String()() Private Function Lookup(ByVal Search_path As String) As Integer Dim i As Integer = 0 Do Until MasterIndex(i)(0) Is Nothing If Search_path = MasterIndex(i)(0) Then …
jayjyli
  • 771
  • 3
  • 11
  • 23
1
vote
0 answers

Fortran index ordering and array syntax

I’m aware of Fortran’s column major ordering and to ensure the inner-most loop is indexing the first dimension of the array. What I’m unsure about is which of the following would be faster: do k=1,100 do j=1, 12 x(:,k) * y(j,:) …
cjp1032
  • 23
  • 3
1
vote
1 answer

How to properly choose which variables should be private/shared/reduced in nested do-loops in Fortran with openmp?

I have the following subroutine, which is my stepper function in a bigger DEM program. It computes every interaction between particles i and j, then updates the forces. I am now trying, as a first effort, to parallelize this thick O(N^2) loop,…
Sogapi
  • 13
  • 4
1
vote
2 answers

VBA: Ending a Do Loop when Cell used in Vlookup is Blank

New to VBA, and I'm attempting to build a Macro that will loop through data that is using a Vlookup to fill in one cell that connects to a different Excel Sheet. I've successfully been able to get the Macro to work, however, it won't stop! My goal…
ccolletti
  • 13
  • 3
1
vote
2 answers

Keep adding numbers into an array until a = 0

Hi I'm new to javascript and I'm sorry if my question is silly for you. This question was solved with the following code: let arr = [12, 6, 53] let a do { a = prompt("Enter a number") a = Number.parseInt(a) arr.push(a) } while (a !=…
Soham
  • 21
  • 3
1
vote
2 answers

Is it possible to optimize these fortran loops?

Here is my problem: I have a fortran code with a certain amount of nested loops and first I wanted to know if it's possible to optimize (rearranging) them in order to get a time gain? Second I wonder if I could use OpenMP to optimize them? I have…
User3000
  • 11
  • 2
1
vote
1 answer

vba loop no checking for duplicate part number

I need my loop to check for existing part numbers and only if there is no existing part number to add it to my table. If the part number already exists, to have a message box stating that it already exists. Its adding it to my table just fine, but…
1
vote
1 answer

SAS do loop for testing covariance structers in PROC MIXED and saving/appending outputs

I am doing repeated measure analysis in SAS and I am comparing the differences in the covariance structure information criteria. Rather than just doing each individual analysis I am looking for a way to loop through them and save the outputs to a…
the_kipper
  • 47
  • 5