Program Qbasic Kondisi

  •  qbasic
  • 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 :

    DIM Num1 AS INTEGER
    DIM Num2 AS INTEGER
    
    CLS
    
    INPUT "Enter First Number: ", Num1
    INPUT "Enter Second Number: ", Num2
    
    IF Num1 > Num2 THEN
      PRINT Num1; "Is Greater Than"; Num2
    ELSEIF Num2 > Num1 THEN
      PRINT Num2; " Is Greater Than"; Num1
    ELSE
      PRINT The Numbers Are The Same
    END IF
    
    END
    

    Output Program 1 :

    Contoh Program 2 :

    DIM KeyPressed AS STRING
    
    CLS
    
    INPUT "Please Enter A Key (A,B,C,D): ", KeyPressed
    KeyPressed = UCASE$(KeyPressed)
    
    PRINT
    
    SELECT CASE KeyPressed
      CASE "A"
         PRINT "A Was Entered"
      CASE "B"
         PRINT "B Was Entered"
      CASE "C"
         PRINT "C Was Entered"
      CASE "D"
         PRINT "D Was Entered"
      CASE ELSE
         PRINT "Some Other Key Was Entered"
    END SELECT
    
    END
    
    UCASE$ : Membuat huruf besar (Uppercase).

    Output Program 2 :

    Comments