IonicWind Software

IWBasic => General Questions => Topic started by: gaza on August 20, 2008, 07:08:42 AM

Title: breakfor
Post by: gaza on August 20, 2008, 07:08:42 AM
def aa:string
c=0
for a=1 to 5
   for b=1 to 5
   if b=2 and a=2 then c=c+1 :BREAKFOR
print b,
next b:print
NEXT a
print c
input aa
i might be missing something here.I think if b=2 and a=2 then and only then would that line be processed and the breakfor would happen then.
Instead breakfor is being processed all the time. This does not happen with other basic's.
can any one shed some light on this

Title: Re: breakfor
Post by: Ionic Wind Support Team on August 20, 2008, 09:03:26 AM
Only one statement after the THEN is part of the IF statement.  The compiler sees this:

def aa:string
c=0
for a=1 to 5
   for b=1 to 5
   if b=2 and a=2 then c=c+1
   BREAKFOR
print b,
next b:print
NEXT a
print c
input aa

So you need a block IF:

def aa:string
c=0
for a=1 to 5
   for b=1 to 5
   if b=2 and a=2
      c=c+1
      BREAKFOR
   endif
print b,
next b:print
NEXT a
print c
input aa
Title: Re: breakfor
Post by: gaza on August 21, 2008, 01:40:22 AM
Thanks Paul for your reply
I had already changed my program to the block form but was just wondering why it executes the line.
As i say on most other basic's that i use anything after the 'then' is executed only when the first part is true.
I guess it is just what you get used to. I am just new to ebasic. Like many others that i have read on the forum i do miss the simplicity and ease of ARRAY'S like in the other basic's but i guess if it takes a few more lines of code and less sleep time thats the price we have to pay.
All the best Garry - in Aussie
Title: Re: breakfor
Post by: Ionic Wind Support Team on August 21, 2008, 02:00:23 AM
?  Emergence has arrays, so I am not sure what you are referring to.

The : is a line separator, the same as pressing return.  I used the same standard the MS basics use.

If you want it on one line you can use the line separator and an end if...

if b=2 and a=2 : c=c+1 : breakfor : endif

Paul.
Title: Re: breakfor
Post by: hugh on August 21, 2008, 05:50:58 PM
Thanks for that one Paul,
I did'nt know that could be done on one line, especially with the colon.
if b=2 and a=2 : c=c+1 : breakfor : endif

Unless i am mistaken, in the old versions of basic, 1970/80, ":" meant  a new line, thus a new , command/instruction.
The ";" had to be used for a continuation, that is if my memory is not yet senile.


Regards

Hugh
Title: Re: breakfor
Post by: Boris on August 21, 2008, 06:50:46 PM
"i do miss the simplicity and ease of ARRAY'S"


openconsole
dim x[10] as int   'single dimensional array of 10 elements of type INT

for n=0 to 9
x[n]=n*n
next n

for n=0 to 9
print using("####",x[n]),
next n

print:print
dim xy[10,10] as int    'two dimensional array of 10*10 elements of type INT

for y=0 to 9
for x=0 to 9
xy[x,y]=x*y
next x
next y

for y=0 to 9
print
for x=0 to 9
print using("####",xy[x,y]),
next x
next y

do:until inkey$>""
closeconsole