April 27, 2024, 06:47:00 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


breakfor

Started by gaza, August 20, 2008, 07:08:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gaza

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


Ionic Wind Support Team

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
Ionic Wind Support Team

gaza

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

Ionic Wind Support Team

?  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.
Ionic Wind Support Team

hugh

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

Boris

August 21, 2008, 06:50:46 PM #5 Last Edit: August 21, 2008, 06:53:04 PM by Boris
"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
Thank you for not breeding