Practice makes perfect


#1

Hello all.
My program keeps crashing due to it being an infinite loop but i don't know how to make it stop.
Here is my code:
var count = 0;

var loop = function(){
while(count <= 3){
console.log("I'm looping!")
}
};

loop(count++)

Any help would be great.


#2

count++ should be after console.log
like:
console.log("I'm looping!")
count++
}
}
loop();

ok?
Any question?
@theocanes


#3

Thats great... thank you
One question what is the loop() at the end do?


#4

The code in a function is not executed when the function is defined. It is executed when the function is invoked.
Some people use the term "call a function" instead of "invoke a function".
so here loop is a function so you need to call it.
do more function as many as you can to make sense

@theocanes


#5

var ciclo = function()
{
var ciclo = 0
while(ciclo<3)
{

	return"¬°Estoy en un bucle!"+" "+ ciclo
 ciclo++;

}

};

ciclo();


#6

under console.log
count ++
and where you have the count ++ change to count


#7

@2gether This is a reply on which comment?
@webrockstar94596 By using return you exit the function, so using it in a loop will quit the function in the first cycle.


#8

this works, remember using return
var count = 0;

var loop = function(count ){
while(count ++){
//Your code goes here!
return"I am looping!"+" "+ count
count++;

}

};

loop(count ++);