Skip to main content

Conditional Statements

  • Chapter
  • First Online:
PowerShell for Beginners
  • 1581 Accesses

Abstract

Conditional statements are used in code to compare variables or the result from several variables used in a sum or calculation. Conditional statements are used to do different things in your code depending on the values of variables. For example, if your script asks the player in a game if they want to walk into the left room or the right, you would read some input from the keyboard and then see what the player has typed. If they type “left,” then you will use a conditional statement to check if the input string variable equals “left.” If it does, then your code will jump to the code that defines what happens in the room to the left. If the input equals “right,” then the conditional statement will run the code that deals with what happens in the right-hand room. Using conditional statements essentially controls the flow of your code, what happens next when certain conditions are met.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 16.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 16.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2021 The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Waters, I. (2021). Conditional Statements. In: PowerShell for Beginners. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-7064-6_4

Download citation

Publish with us

Policies and ethics