Conditional statements are a feature of every programming language. Windows includes the MS-DOS IF statement, which you'll find useful in batch files and shell scripts. The functionality of the IF statement is fairly straightforward: The OS evaluates a specific condition, and according to the result of the evaluation, the OS performs specified actions.

Windows' IF statement uses the following syntax:

IF \[NOT\] <some condition> <action if condition is true>

For example, to compare two strings you would type

IF WINDOWS<h1><a name="WINDOWS_ECHO_Strings_equal_pre_p_The_result_would_be_a_i_Strings_equal_i_message_p_p_Note_that_in_IF_statements_string_comparisons_are_case_sensitive_In_the_previous_example_changing_one_of_the_WINDOWS_to_Windows_would_cause_the_OS_to_evaluate_the_condition_as_false_and_ignore_the_action_statement_p_p_The_IF_statement_s_optional_NOT_operator_provides_another_way_to_handle_string_comparisons_For_example_consider_the_following_command_p_pre_IF_NOT_WINDOWS">WINDOWS ECHO Strings equal</a></h1>

The result would be a Strings equal message.

Note that in IF statements, string comparisons are case-sensitive. In the previous example, changing one of the WINDOWS to Windows would cause the OS to evaluate the condition as false and ignore the action statement.

The IF statement's optional NOT operator provides another way to handle string comparisons. For example, consider the following command:

IF NOT WINDOWSwindows ECHO Strings not equal

In this example, WINDOWS (i.e., all capital letters) doesn't equal windows (i.e., all lowercase letters); therefore, the OS will display a Strings not equal message.

To use the IF statement to check whether a file exists, slightly change the basic syntax:

IF \[NOT\] EXIST <filename> <action if file exists>

For example, you might use

IF EXIST system.ini type system.ini

If system.ini exists, the OS will display the file's contents. Or, you might use

IF NOT EXIST system.ini type system.ini

If system.ini doesn't exist, the OS generates an error message.