3: A Fellow of Infinite Loops


#1


https://www.codecademy.com/courses/javascript-beginner-en-ASGIv/0/3?curriculum_id=506324b3a7dffd00020bf661#


My code is accepted by CodeAcademy but I'm just trying to gain a deeper understanding being that I've had a few days away from CodeAcademy and its a little hazier than it was then, but also because there is no context.

If we have a understand=true; statement that prompts the output "I'm learning while loops" and a understand=false; statement which prompts the output "Guess I'm not learning while loops; what is the REAL WORLD application of such a statement usage? It a little obscure and so I don't feel like i'm really internalizing it because it has no connection to an actual application.

Its like I can 'do' it but I can't 'see' it! If you had to 'act out' this code, what would it look like? ie metaphor etc

thank you to anyone who could shed a little light on this for me! :wink:


understand = true;

while(understand){
	console.log("I'm learning while loops!");
	//Change the value of 'understand' here!
	understand=false;
	console.log("Guess I'm not properly learning 'while' loops!");
	
}


#2

uhm... no?

here you declare a variable called understand and give it a value of true:

understand = true;

then you have a while loop:

while(understand)

understand is true, so this condition evaluates to true, the loop will start running

console.log("I'm learning while loops!");

here we log something to the console.

understand=false;

we update our variable understand, we assign it a new value of false

console.log("Guess I'm not properly learning 'while' loops!");

we log another string to the console

now, the loop will evaluate the condition again:

while(understand)

We updated understand to false, so now the loop condition will evaluate to false, the loop will exit, the program is done


#3

What would be an actual input requirement similar to 'understand' that would begin a loop? Maybe a credit card number that starts with a certain number to indicate whether or not its visa, mc, or amex maybe? Or, is this more of an if/else loop? thanks


#4

(i think i might be approaching it too 'literally' and seeing the actual word 'understand' as part of a philosophical logic statement rather than as an arbitrary value in a string! - hence: overthinking!)


#5

while will start the loop, understand is the condition of the loop, to determine if the loop needs another iteration or that the condition is met, and the loop can exit

You could make a loop to keep running until someone enters a valid credit card number, and you can use if/else if/else to determine if the number is visa or mc

if/else are not a loop


#6

thank you stetim94 :slight_smile:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.