What I self studied is that an accidental stays throughout the measure to the bar. Lately I saw in a theory work book, there's two conditions 1. The same note. (That's ok with me) 2. It's on the same line or pitch, if it's higher or lower it doesn't change, it's stay how it's written with no accidental. What is right?
Accidentals do only last though the measure, but they do not apply to all octaves of the note they only apply to the octave applied.
The first note is Eb, the second is E even thought it is in the same measure as the Eb because it is in a different octave. The last is E because the effect of the applied flat is only for the measure.
Accidentals also don't apply to diffrent staffs as seen here: Do accidentals apply to other staffs of the same type?
This is a response to redirected question Do accidentals last for the entire measure?
There are actually two issues to consider with accidentals:
What a performer should do given a piece of notation.
Whether a publisher should attach an accidental to a note which has the same pitch as the last time it was played.
From a publishing standpoint, certain constructions should be regarded as though they are ambiguous, and thus include a natural whether or not it would actually alter a note's pitch. Performers who encounter such constructions will need to select a pitch to perform, and in many cases having select different pitches would be worse than having all performers select the better pitch or having all select the worse pitch, so performers need consistent rules.
Technically, accidentals only affect notes at the same staff position which are written for the same part. If soprano and alto parts for a piece in e.g. C major are printed together on a treble staff and the soprano has a mid-line Bb accidental on beat one while the alto part had a G on that beat, a mid-line B in the alto part later in the measure should be performed as a B natural unless otherwise marked. If there are no other accidentals, the alto's part wouldn't contain a Bb accidental and thus the alto would have no reason to sing a Bb.
On the other hand, even if there should technically be no reason for an alto to sing a Bb there, it's likely that many altos who sing that note would notice that there was a Bb earlier in the measure and not take the time to notice which part it was attached to. Further, even if altos do notice that the only Bb in the measure is attached to the soprano part, they might reasonably believe that the absence of a flat on their note was a mistake.
To avoid such confusion, there are certain situations where accidentals should be included even if a pitch should be performed identically in their absence:
If within a measure, the same letter pitch appears in different octaves, different staff positions, or different parts, and any of them has an accidental, any simultaneous or succeeding use of that same letter pitch in the measure should generally be marked with an accidental unless it is preceded by a matching accidental in the same octave, staff position, and part.
If a slur (as distinct from a tie) connects a note in one measure to a note in the succeeding measure, and the first is altered from the key signature but the second is not, the second should have an accidental applied to indicate that the pitch changes. While ties and slurs should be visually distinct from each other, that doesn't mean they can't be confused; adding an accidental would make clear that the slur is not a tie.
If a melodic figure is similar to one that has appeared previously, but the previous version used accidentals to alter pitches in places the later one does not, the notes in question should be marked with accidentals to indicate that the latter version is to be performed differently (and ensure that the lack of accidentals is not presumed to be a misprint).
As to whether cautionary accidentals should be marked with parentheses, that is a matter of judgment which should, when possible, be made based upon whether a performer who is sight-reading a piece would be likely to think the pitch would be without an accidental. If an alto line has a bottom-line Eb accidental on beat 1 and the soprano has a top-space E natural on beat 4, a natural written without parentheses in the soprano part would likely cause confusion since a soprano who was sight reading would have no reason to think their note was anything other than an E natural. If, however, a slur connects an altered note in one measure to an unaltered note in the next, parentheses around an accidental may erroneously make a performer think the note's pitch doesn't change even though it does.