Presentation is loading. Please wait.

Presentation is loading. Please wait.

State Diagrams and enums ECE152. Overview What is a state diagram and where are they used? – Digital Logic – Coding Why use a states? How are states done.

Similar presentations


Presentation on theme: "State Diagrams and enums ECE152. Overview What is a state diagram and where are they used? – Digital Logic – Coding Why use a states? How are states done."— Presentation transcript:

1 State Diagrams and enums ECE152

2 Overview What is a state diagram and where are they used? – Digital Logic – Coding Why use a states? How are states done in code?

3 Why use states? States let your functions ‘be aware’ of what is going on in the program currently They allow for easy partitioning of modes They are easy to understand while leaving out the language

4 How are states done in code? You need a state variable You could use any data type, but you have to remember what each state means. What if there are 100s of states?

5 Using enum makes things better No numbers or weird code to remember enum states { state1, state2, state3} state; Look, descriptive names enum states { start, stop, clear} state;

6 Use a switch statement Switch statements are much ‘cleaner’ than nested if statements

7 Example Look at this sample program. From what it does, lets draw a state diagram.

8 Things to Remember States give a framework to write code


Download ppt "State Diagrams and enums ECE152. Overview What is a state diagram and where are they used? – Digital Logic – Coding Why use a states? How are states done."

Similar presentations


Ads by Google