The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Odd Behaviour in For Loops

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Nai Posted - 05/30/2005 : 12:23:22 PM
Origin Version (Select Help-->About Origin): Originro 7.5 SR5
Operating System: Windows 2000

For some reason I hit a general operation failure whenever I hit element v[498] WITHIN the FOR LOOP in the following subroutine:
int subMaxIndex(vector<double>& v){
printf("\n v[497] = %f", v[497]);
printf("\n v[498] = %f", v[498]); //it prints here
printf("\n v[499] = %f", v[499]); //it prints here
printf("\n v.GetSize() = %d", v.GetSize());
for(int i=0; v[i]<v[i+1] && i<499;i++){ //it does not exceed v[498 here]
printf("\n v[%d] = %f", i,v[i]);
}
if(i==v.GetSize())
return -1;
return i;
}

Notice that I can access vector elements 498 and 499 outside of the FOR loop, but not inside it in the expression 2 condition.
Odd? or is it just me!
1   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 05/30/2005 : 1:13:11 PM
Try reversing the order of your conditions...

for(int i=0; i<499 && v[i]<v[i+1]; i++)

...I suspect that v[499] is the last element and the error occurs when the condition v[499]<v[500] is tested. Testing i first avoids that.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 05/30/2005 1:20:09 PM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000