Control

Wait

wait(1)
// Example: wait()
exampleSprite_sprite.whenFlag(function() {
   this.show()
   this.say('Start')
   this.wait(1)
   this.say('1 second later')
})

Repeat

for (var counter = 1; counter < 11; counter++) {
  /* your code */
}
// Example: repeat
exampleSprite_sprite.whenFlag(function() {
   for (var counter = 1; counter < 11; counter++){
      this.say('Repeat Loop Iteration: ' + counter)
      console.log(counter)
      this.wait(1)
   }
})

Forever

while (true) {
  /* your code */
}
// Example: forever
exampleSprite_sprite.whenFlag(function() {
   while (true){
      this.nextCostume()
      this.wait(1)
   }
})

If Then

if (yourCondition) {/* your code */}
// Example: if then
exampleSprite_sprite.whenFlag(function () {
    while(true){
        this.say("waiting for you to press the up arrow key")
        if (stage.isKeyPressed('ArrowUp')) {
            this.say("Up Arrow key was just pressed")
            this.wait(1)
        }
    }
})

If Then Else

if (yourCondition) {
  /* your code */
} else {
  /* your code */
  }
// Example: if then else
exampleSprite_sprite.whenFlag(function () {
   while(true) {
      if (stage.isKeyPressed('ArrowUp')) {
         this.say("Up Arrow key was just pressed")
         this.wait(1)
      } else {
         this.say("waiting for you to press the up arrow key")
      }
   }
})

Wait Until

//use JS conditional while loop as below
// Example: wait until
var wait_condition = true
exampleSprite_sprite.whenFlag (function () {
   while (wait_condition === true) {
      wait_condition = !stage.isKeyPressed ('ArrowUp')
      this.say ('just doing nothing until the wait condition becomes true')
      this.wait (0)        // stops older devices from lagging
   }
   this.say ('Move on to next code line because the wait condition is now true')
})

Stop All

//stop all using conditional while loop- see example below: 
// Example: stop all using conditional while loop
var forever_condition = true
exampleSprite_sprite.whenFlag(function() {
   while (forever_condition === true){
      forever_condition = !stage.isKeyPressed ('space')
      this.say ("I'm in the forever loop- press space bar to stop loop")
      this.nextCostume()
      this.wait(0.1)
   }
   this.say ("I've broken out of the forever loop now and stopped code loop")
})

Clones

When I Start as a Clone:

whenCloned(function (){                                 
    this.alive = true
    this.addTo(stage)
    /*your code*/
    })

Create Clone:

myself.clone()

Delete Clone:

removeFrom(stage)
alive = false

Clone Example:

// Examples: delete - clone - whenCloned
exampleSprite_sprite.whenFlag(function() {
    exampleSprite_sprite.show()
    this.sayWait('Make some clones',1)
    while(true){
        exampleSprite_sprite.clone()
        this.wait(1)
    }
})
exampleSprite_sprite.whenCloned(function (){               
    this.alive = true
    this.addTo(stage)
    while(true){ 
        this.move(10)    
        if (this.isTouchingEdge() ){
            this.removeFrom(stage)          
            this.alive = false
        }
    }
})