Kali ini saya akan memberikan contoh program qbasic dengan menggunakan kondisi.
Jadi program kali ini memakai struktur pemilihan, seperti IF-CONDITION dan SELECT-CASE.
Struktur IF-THEN :
If <condition> Then
Do something
ElseIf <condition> Then
Do something>
Else
Do something
End If
Struktur SELECT-CASE :
SELECT CASE KeyPressed
CASE "A"
Do something
CASE "B"
Do something
CASE ELSE
Do something
END SELECT
Contoh Program 1 :
DIMNum1ASINTEGERDIMNum2ASINTEGERCLSINPUT"Enter First Number: ",Num1INPUT"Enter Second Number: ",Num2IFNum1>Num2THENPRINTNum1;"Is Greater Than";Num2ELSEIFNum2>Num1THENPRINTNum2;" Is Greater Than";Num1ELSEPRINT“TheNumbersAreTheSame”ENDIFEND
Output Program 1 :
Contoh Program 2 :
DIMKeyPressedASSTRINGCLSINPUT"Please Enter A Key (A,B,C,D): ",KeyPressedKeyPressed=UCASE$(KeyPressed)PRINTSELECTCASEKeyPressedCASE"A"PRINT"A Was Entered"CASE"B"PRINT"B Was Entered"CASE"C"PRINT"C Was Entered"CASE"D"PRINT"D Was Entered"CASEELSEPRINT"Some Other Key Was Entered"ENDSELECTEND