Skip to content
  • for
  • for in
  • for of
  • while
js
// example1
for (var i = 0; i < 10; i++) {
  console.log(i)
  break
}
console.log(i)

// example2
for (var i = 0; i < 10; i++) {
  continue
  console.log(i)
}
console.log(i)

// example3
for (var i = 3; i < 12; i++) {
  if (i < 3) {
    i++
    break
  }
  if (i > 0) {
    i += 2
    continue
  }
  i--
}
console.log(i)

// example4
// a++ a += 1 a = a + 1 都是在自身基础累加1
// 但是a++浏览器会做特殊数量 ,会把其转化位数字再进行累加
// a++ <=> a = Number(a) + 1
// a += 1 <=> a = a + 1
// 1. Let lhs be the result of evaluating LeftHandSideExpression.
// 2. Let oldValue be ToNumber(GetValue(lhs)).
// 3. ReturnIfAbrupt(oldValue).
// 4. Let newValue be the result of adding the value 1 to oldValue, using the same rules as for the + operator
// (see 12.7.5).
// 5. Let status be PutValue(lhs, newValue).
// 6. ReturnIfAbrupt(status).
// 7. Return oldValue.

let a = '10'
a == 10 ? a++ : a--
console.log(a) 

let b = '10'
console.log(b+=1) 

// example5
let b = '10'
switch (b) {
  case 10:
    b++
    break
  default:
    b--
}
console.log(b)