Zum Hauptinhalt springen
IT Security NachrichtenGoogle Tests AI Data Center In Space(03.10.2026 um 09:00 Uhr)
••
IT NachrichtenBahrain GP in Malaysia: How to Watch the F1 Race(03.10.2026 um 09:00 Uhr)
••••••••
IT Security NachrichtenGoogle Tests AI Data Center In Space(03.10.2026 um 09:00 Uhr)
••
IT NachrichtenBahrain GP in Malaysia: How to Watch the F1 Race(03.10.2026 um 09:00 Uhr)
••••••••
Intelligence View
⚡ tsecurity.de Intelligence

Go Learning Notes - Part 3: If, Else If, Else Statements

Today I improved my Go Conference Booking App by adding conditional logic and better loop control. Instead of allowing any booking, I now validate user input…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

Today I improved my Go Conference Booking App by adding conditional logic and better loop control. Instead of allowing any booking, I now validate user input using if, else if, and else statements.



Here’s what I learned:






Boolean Expressions in Go



In Go, conditions inside if statements must evaluate to a boolean (true or false).



Example from my program:




if userTickets < remainingTickets






This expression returns:





  • true - booking is allowed


  • false - booking is denied



Comparison operators I used:

< less than

== equal to

> greater than





If Statement (Main Booking Logic)





if userTickets < remainingTickets {
remainingTickets = remainingTickets - userTickets
bookings = append(bookings, fName+" "+lName)
}





What This Does:




  • Checks if enough tickets are available

  • Deducts tickets

  • Saves the booking

  • Displays confirmation



This made my app smarter and prevented overbooking.





Else If Statement





else if userTickets == remainingTickets {
// do something else
}





This condition handles the case where:




  • The user books exactly the remaining tickets
    It allows handling a special edge case separately.





Else Statement (Invalid Booking)





else {
fmt.Printf("We only have %v tickets, so you can't book %v tickets.\n", remainingTickets, userTickets)
}





This runs when:




  • The user tries to book more tickets than available



Now my program protects against invalid input.





Infinite Loop with Condition-Based Exit



The booking system runs inside:




for {






This creates an infinite loop.



But I added a stopping condition:




if remainingTickets == 0 {
fmt.Println("Our Conference is fully booked. Come back next year!")
break
}









break Statement



The break keyword:




  • Immediately exits the loop

  • Stops the program once tickets are sold out



Without break, the loop would continue forever.



Today I learned how to use boolean expressions and if, else if, and else statements to control the flow of a Go program. I practiced validating user input and handling different booking scenarios to prevent overbooking. I also learned how to use break to stop an infinite loop when tickets are sold out. Combining conditionals with loops and slices made my program smarter and more dynamic.

🔍 CTI & Forensik

Cyber Threat Intelligence & Forensik

ATT&CK-Navigator · IoC-Radar · Exploit-Belege
CTI Threat Relationship Graph
Akteure · Techniken · Beziehungen
2 Knoten · 1 Relationen
CVE / Incident Threat Actor Software MITRE ATT&CK CWE Weakness IoC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Go Learning Notes - Part 3: If, Else If, Else Statements

Thematisch verwandte Begriffe: Learning, Notes, Part, Else · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Nächster Beitrag