comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » For..Do Loop and If statements
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
For..Do Loop and If statements [message #94095] Wed, 18 January 2017 21:18 Go to previous message
smnadoum is currently offline  smnadoum
Messages: 24
Registered: June 2016
Junior Member
I have written a couple of for.. do loops, however, they don't work properly. Not sure what I did wrong.

1) I want to use a for..do loop and if statements to derive indices. where 'a' is greater than 5, and output the result to new variable 'b2'

a is INT = Array[4, 5, 3]
b2=[a]
b2=[]
for i=0, n_elements(a) -1 do begin
temp =a[i]
if temp gt 5 then b2=[b2,temp]

2) I want to loop through the elements of d and use an if statement: if the element of d is equal to 20 then divid that element by a floating point 5, and if the element is not equal to 20 then divide it by a floating point 3.


d is INT = Array[4, 5]
for i=0, n_elements(d)-1 do begin ;if statement eq to 20 then divid by 5. ne 20 then divide by 3.
if d(i) eq 20 then print, 20/5.
if d(i) ne 20 then print, 20/3.
endfor
end


None of these statements work and I don't know why.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL 8.6 demo mode
Next Topic: How to run correl_optimize IDL code

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:33:20 PDT 2025

Total time taken to generate the page: 0.00399 seconds