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
 Origin Forum
 What am I doing wrong with 'for'?

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
Jose Posted - 03/22/2002 : 11:41:56 AM
Imagine that for any reason I have a string that is a number followed by an undetermined number of characters, and I want to get that number for operations. I was trying something like

%a=1230abcd;
for (;%a/1==0;) {%a=%[%a,%[%a]];};


That's because %a/1 returns cero while %a is not numeric, and inside the 'for' I remove the last character in every loop.

But this doesn't work, and I don't know why. But that logical condition works fine inside an 'if', so this alternative works fine:


%a=1230abcd;
ii=0;

for(;ii==0;) {
if (%a/1==0) {%a=%[%a,%[%a]];}
else ii=1;
}


Do you know why does that work in an 'if' but not in a 'for'?


- Jose Viņa
Origin WebRing member


Edited by - Jose on 03/22/2002 12:10:10
2   L A T E S T    R E P L I E S    (Newest First)
Jose Posted - 03/22/2002 : 12:41:42 PM
I was thinking that inside the 'for' any logical expression was valid. Thanks for the remark, I'll try to remember it. My final version is

%a=1230abcd;
ii=0;

for(;1;) {
if (%a/1==0) {%a=%[%a,%[%a]];}
else break;
}


- Jose Viņa
Origin WebRing member


Edited by - Jose on 03/22/2002 12:46:03
Laurie Posted - 03/22/2002 : 12:19:11 PM
Hi Jose,

It's because you need a numeric variable when using a for loop and the same is true when simulating a while loop with the for command.

With an if statement, the expression is evaluated as true or false.

Laurie

OriginLab Technical Support

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