×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

# 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.

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!