×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Conditional IF statement

Conditional IF statement

Conditional IF statement

(OP)
Hi,

I have the foll 3 lines in a QBASIC code.

Is there a way of combining all 3 lines or at least combine into 2 lines?

IF 2^K = N GOTO 100
IF 2^K < N GOTO 110
IF 2^K > N GOTO 120

Thanx

pya

RE: Conditional IF statement

Hi pya,
You can compute X = SGN(2 ^ K - N) + 2
which delivers results:
X = 1 when 2 ^ K < N
X = 2 when 2 ^ K = N
X = 3 when 2 ^ K > N
and then you can use for branching ON .. GOTO statement
like ON X GOTO 110, 100, 120

Here is an example which works in QB64:
on_goto.bas

CODE

CLS
INPUT "K = ", K
INPUT "N = ", N

REM if 2 ^ K < N then X = 1
REM if 2 ^ K = N then X = 2
REM if 2 ^ K > N then X = 3
REM X = SGN(2 ^ K - N) + 2
REM PRINT "X = ", X

ON SGN(2 ^ K - N) + 2 GOTO less, equal, greater

less:
PRINT "2 ^ K < N"
END

equal:
PRINT "2 ^ K = N"
END

greater:
PRINT "2 ^ K > N"
END 

RE: Conditional IF statement

(OP)
Thanx mikrom.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close