I am converting GW-BASIC code to C# and have very limited experience in BASIC languages in general. I am trying to understand how IF...THEN...GOTO statements behave. For example, I have the following statement:

85 IF M(3,1)>M(2,1) THEN 95
90 M(3,1)=M(3,1)+P2
95 Z1=R1*(90.567-41.685/M(2,3))

My question is this: if the condition at line 85 is not met, will it still execute code at line 95, or does it skip it?

Any direction would be greatly appreciated...

有帮助吗?

解决方案

Yes, regardless of the evaluation of the Boolean condition at line 85, line 95 will be executed BUT if 85 evaluates to true, then line 90 will be jumped and thus won't be executed.

其他提示

It will execute the code at line 95. The then statement cause the program to jump to line 95 and execute that line.

It's equivalent to this:

if ( M[3,1] <= M[2,1] ) {
   M[3,1] = M[3,1] + P2
}
Z1=R1*(90.567-41.685/M[2,3])

Apparently the code snippet has a pseudo IF/ELSE structure, the logic seems like:

If the condition of line 85 is not meet then QBasic continues with 90 and then 95. If the condition of line 85 is meet then QBasic continues with 95 and forward.

THEN 95 is short for THEN GOTO 95, which jumps the execution pointer to line 95.

REMLINE.BAS is a program to remove line numbers from Microsoft Basic Programs. It removes only those line numbers that are not the object of one of the following statements: GOSUB, RETURN, GOTO, THEN, ELSE, RESUME, RESTORE, or RUN.

BaCon and BCX can turn your BASIC into C.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top