Instructions say 1. Initialize some state variables. I am clueless what that even means. I know I am starting with three and changing x as it goes up toward 1,000. I know I only want odd numbers, so, I know x=3, then x=x+2, but, I am confused about initializing state variables. What does that even mean?
in this context a state variable is used to hold or keep track of something that changes during program execution but gets used as it changes - i just made that up ... for example: you might have a variable isPrime that you initialize to True and it stays True till you find out that it is False or you might have a variable that is keeping track of the current number that is being tested for primeness or a variable that is keeping track of how many primes that have been found things like that
i don't think so if it is right. but still i will share. maybe it could help. let me say that the x=3. x=x+1 till it reach 1000. number = x/2 if x - (number * 2) = 0 then {x is an even #} else if x - (number * 2) =1 then {x is an odd #} that is all i can do. and hoping that it helps
For any variable you plan to use, "state variable" refers to the value you give it before anything happens to it. Your state variable would be a statement containing a variable name, an assignment operator, and a value. For example, "X = 0" or "Y = 1"
A state variable is a variable that is used to keep track of where you are in your program. A state variable in this case could be a counter, that you increment every time you find a prime number. So you could start your counter at one (since 2 is a prime number) and then run through all odd numbers checking to see if they are prime. If so, your counter increments by one. The loop ends when your state variable (counter) reaches 1000. hopefully this helped :)
Join our real-time social learning platform and learn together with your friends!