while文で2から10までの2の倍数を出力するにはどのようなプログラムを書けば実行できますか?
実行回数が決まっているならば、
forの方がいい気がしますが。
丸投げ作業依頼はやめましょう。
まずは自分でコードを記載してみて、
それでもわからない、理想の処理ができない、という質問にしましょう。
while (true) {
console.log("2 4 6 8 10");
}
while (true) {
const a = Math.floor(Math.random() * 100);
if (a % 2 === 0 && a >= 2 && a <= 10) {
console.log(a);
}
}
while (true) { console.log(2); }
const array = Array.from({ length: 10 }).map((a, i) => i * 2).filter(a => a >= 2).filter(a => a <= 10).reverse();
while (array.length > 0) console.log(array.pop());
const array = Array.of(10);
let i = 1;
while (i < 9) {
i <<= 1;
array.push(i % 10);
}
console.log(array);
function* g() {
let i = 1;
while (i < Number.MAX_SAFE_INTEGER) {
yield i * 2;
i++;
}
}
for (const i of g()) {
if (i > 10) break;
console.log(i);
}
const f = value => {
if (value < 0) return 0;
return [value, f(value - 2)];
};
let result = f(10);
while (result.length > 1 && result[0] > 0) {
console.log(result[0]);
result = result[1];
}
let i = 4;
while (i > 0) {
console.log(6 - i);
console.log(6 + i);
i -= 2;
}
console.log(6 - (i * 2 >> 3 & 4 ? 5 : 0));
let i = 100;
while (i < 99999999999) {
console.log(Math.log10(i));
i *= 100;
}