Loop structure
PowerScript
Basic Syntax
main
1 file
Loop structure..js
Loop.js
894.0 B
Loop structure..js
957 bytes
// for
for(var i = 0; i <= 10; i++){
print(i + "\n")
}
// while
var count =0;
while (count<10) {
count ++
print(count)
}
// for-in with array
var array = [1,2,3]
for (var i in array){
print(array[i])
}
// for-in with object(JSON)
var object = {2:3 ,1:2, 3:1}
for (var p in object){
print(object[p])
}
// Nested for loop: multiplication table
for (var i = 2; i < 10; i++){
print("--" + i + " times table --")
for (var j=1; j<10; j++){
print(i +" x " + j + " = " +i * j)
}
}
// Nested for-in loop with arrays: multiplication table
var numbers = [2, 3, 4, 5, 6, 7, 8, 9];
var multipliers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
for (var i in numbers) {
var timesTable = numbers[i];
print("-- " + timesTable + " times table --");
for (var j in multipliers) {
var num = multipliers[j];
print(timesTable + " x " + num + " = " + timesTable * num);
}
}
Comments (0)
No comments yet. Be the first to comment!
Snippet Information
Author:
jungyu.lee
Language: PowerScript
Created:
Oct 24, 2025
Updated:
0 minutes ago
Views: 33
Stars: 1