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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 What am I doing wrong with 'for'?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Jose

Netherlands
93 Posts

Posted - 03/22/2002 :  11:41:56 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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 Via
Origin WebRing member


Edited by - Jose on 03/22/2002 12:10:10

Laurie

USA
404 Posts

Posted - 03/22/2002 :  12:19:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

Jose

Netherlands
93 Posts

Posted - 03/22/2002 :  12:41:42 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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 Via
Origin WebRing member


Edited by - Jose on 03/22/2002 12:46:03
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000