Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAditya Puri
1,080 PointsWhat does the term "state" mean?
He uses the term "State" a lot in the video.
For eg. lets update the "state" now.
Can anyone explain what the term "State" means?
5 Answers
Ilya Dolgirev
35,375 PointsActually, it's very simple :)
Just imagine light switch. It has 2 states - on
and off
. Updating the state means changing the state.
When you turn light on you updating the state of that switch from off
to on
.
For boolean variables it means changing from true
to false
and vice versa.
For int variables you update the state after some math operations.
Ilya Dolgirev
35,375 PointsProgram state( or object state) is little bit more complex that single variable state :) Just imagine central panel with light switches. Actual state of this panel is based on states of switches. If you changed one, the whole state for the panel is changed.
The same idea is for object or program. If you update state of one of your variable the program state also changes.
Ilya Dolgirev
35,375 Pointsint counter = 0; // Initial state
counter = counter + 1; // You've changed(updated) the state of counter
Aditya Puri
1,080 Pointsoh, so thats all state means? Updating variables and changing boolean values for different parts of the program or based on user interactions?
Ilya Dolgirev
35,375 PointsYep, you've got the main idea! :) But managing complex program state is not so simple as a single variable. Sometimes you'll have to spend hours to get where the bug is :)
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsSo a program state is as simple as a the value of a variable including but not limited to booleans? :)
Aditya Puri
1,080 PointsAditya Puri
1,080 PointsFor int variables you update the state after some math operations.
. I don't understand this line.