15.01.2024 Views

CompTIA A+ Certification All-in-One Exam Guide

  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

computer to remember the value by naming it; we call these named values

variables. My office phone number is saved as the variable phone_number:

phone_number = "281-922-4166"

A variable in a scripting or programming language is a named value or

thing. The CompTIA A+ objectives refer to a variable as a basic script

construct, meaning, I think, concept.

Conditionals and Basic Loops

Once you move beyond the most basic shell scripts—those that are just a list

of commands—you often need to control when and how different commands

run. Not surprisingly, more sophisticated scripting languages and

programming languages give you excellent tools, called control constructs, to

control commands.

NOTE I’ve included some scripting examples in this section. Each one

uses the Python language. If you try to copy them into a script file for another

language, they may not work!

The most basic control constructs are conditionals. Conditionals enable

you to specify code that should run only when some condition is (or is not)

met. Most languages have keywords, such as an “if” statement. The “if”

statement specifies a condition, and what code to run if the condition is met.

Here’s a simple example:

Here’s what each line means:

1. The animal variable holds a string called “cow”.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!