Another type of control structure is called a conditional statement. In this case, the typical flow of executed commands is interrupted such that certain commands are only executed under certain conditions. If those conditions are not met, then those commands are not executed.

 

Conditional statements make it possible for our computer programs to make decisions. This makes our computer more flexible, responsive, and intuitive to us as programmers. We make decisions using conditional statements regularly in our lives.

 

As a simple example, many people check the weather forecast before starting their day. If it is going to rain, then you take an umbrella with you. Otherwise, you leave your umbrella at home. The same concept is true in our programming language.

 

Using an example from audio, a dynamic range compressor behaves a lot like a conditional statement. If the amplitude of an input signal is greater than a threshold, then the compressor will decrease the amplitude of the signal. If the amplitude is not greater than the threshold, then the compressor allows the signal to pass unchanged.

 

One type of conditional statement in Matlab is called an “if” statement. When using an if statement, a boolean expression is evaluated to be true or false. If the statement is true, then the commands immediately following the if statement are executed. Otherwise, those commands are skipped.

 

 

Conditional statements evaluate boolean expressions based on the logical data type. 

 

Another method for a programmer to control the flow of executed commands is to create user-generated functions.

Receive Updates

No spam guarantee.